#Instantiating entity prefabs in bakers

1 messages · Page 1 of 1 (latest)

spare spindle
#

I am trying to instantiate entity prefabs in a baker for a few reasons including not having to bake multiple game object instances. There doesn't seem to be any way to instantiate a prefab or even to make child entities (at least without a lot of extra work)

As an alternative, I've set up a baking system that instantiates the prefabs, however I get errors because it duplicates the EntityGuid on the prefab and there is no way to correctly create a new one outside of the baking process (it stores counters in the context).

Would it be possible to get some way to instantiate prefabs in the baker itself? Or is diverging from the source game object hierarchy against the goals of baking?

whole lagoon
#

I've tried various methods to instantiate in baker but none have really worked smoothly. My current idea is to have the baking entity create N number of additional entities then in a baking system, instantiate the desired prefab and replace the EntityGuid component with one of the empty additional entities before deleting the old additional entity.

spare spindle
#

I just tried that and it doesn't seem to have any effect on the hierarchy view breaking

whole lagoon
#

I don't know then. I did the manual instantiating method, giant code block using unsafe pointer copies, and the hierarchy worked but the whole process was very fragile. I think if you really want multiple of something at bake, you're gonna have to just clone the original game object the amount of times you want.

silent iron
#

I have another option

#

You create additonal entities

#

And in system

#

Manually solve archetype

#

And then copy all component data

#

Allthough...

whole lagoon
#

Yes, that's what I did for the manual instantiating method

silent iron
#

This won't work with hieararchies

whole lagoon
#

Yea.

silent iron
#

Eh

#

So miserable

whole lagoon
#

Also the problem being to do so would require a lot of code. Just copying over standard struct ICDs took a solid 60 or so lines.

#

Then you have to account for all the other component types: managed, shared, managed shared, buffers.

silent iron
#

I have a method codd that does copy on all types

#

Can be modified to better support this

#

I used it to swap entity into specific index

whole lagoon
#

To do a copy, I had to take the ComponentType -> DynamicComponentTypeHandle -> cast to byte array -> UnsafeUtility.memcpy across both entities.

silent iron
#

Yeah

#

That's what I did either

spare spindle
#

@tough summit I hear you are the person for this

tough summit
#

Instantiating prefabs in a Baker just isn't supported right now

spare spindle
spare spindle
#

Would it also help if I created a sample project with examples of how this could be useful?

#

eg another use I have is a 3d tile manager that uses a few prefabs, but I have to create 100s of game objects for baking instead of creating them all at bake time

tough summit
silent iron
spare spindle