#Pure DOTS without Bakers, how to best setup big archetypes with many components?

1 messages · Page 1 of 1 (latest)

full crescent
#

We have avoided using bakers in our projects and explictly setup our Entities & Components.

Looking at one example, creating a unit or enemy in our game, we manually setup add & configure each component from our ScriptableObject configurations. See a slice in the attached photo. I realize now this may be causing a ton of archetype churn on the main thread as these flows execute.

From some research, if we wanted to optimize these flows, I can see:

  1. We could explore baking, let's just ignore this one for now, not really interested in the baker flows.
  2. We could create and cache an EntityArchetype and use that with CreateEntity to add all the components at once.
  3. We could run the flow once to create a full Entity and cache it as a 'runtime prefab' to then use with CreateEntity to clone it for future spawns.

Struggling to find advice on this topic, any thoughts?

ornate portal
#

If having a prefab makes sense for your use case (components mostly the same between instantiated entities) then go with that.

It's still a good idea to fully create the archetype beforehand in any case. Archetypes don't get cleaned up, so with AddComponent[Data], you'll keep some unnecessary archetypes that never get used but take up space in the limited memory allocation for archetype data (unless that's changed recently?).

haughty fossil
#

It's hard to understand why you have to struggle finding an advice on this particular issue since advices had been given out numerous times here on this dots channel. The answer is either using baker or creating an archetype beforehand.

rancid wyvern
# full crescent We have avoided using bakers in our projects and explictly setup our Entities & ...

You can just put all that code in a baker though. Just have a reference to the scriptable object on an authoring component. Unless you need to have it work runtime too?

If you do need it to work runtime / really really don't want to use a baker then making an archetype or component array beforehand is what makes the most sense. If you plan on spawning multiple entities based on the same scriptable object then you should also use a prefab for it, and just instantiate based on it directly. Basically have one flow that creates the prefab based on the scriptable object on startup/when it changes, and a separate flow that just instantiates the prefab without setting any values other than those that have to be unique for every character, like position