decline-cookies / anvil-unity-dots

Unity DOTS and ECS specific additions and extensions to Anvil
MIT License
4 stars 1 forks source link

EntitySpawnSystem - Devise a way to have definitions spawn extra entities by archetype #192

Closed mbaker3 closed 1 year ago

mbaker3 commented 1 year ago

There is no efficient way to spawn multiple entities from a single IEntitySpawnDefinition. This is common practice for entities that generate other entities as a side effect, own proxy entities, or who's components have been split up for performance reasons.

The solution for this may not add to IEntitySpawnDefinition but instead create another type that wraps/groups many definitions to a higher concept actor/instance.

For now, a workaround has been implemented as part of (#193) that allows a definition to be created within the PopulateOnEntity method of another definition. This workaround gets the job done but isn't as efficient as instantiating from archtype.

Maybe the proper solution is to provide a mechanism to fetch archetypes for a given definition as needed. That's really the only piece missing here. If this is the direction we take consider whether all definitions should be instantiated through the IEntitySpawnDefinitionExtension.CreateAndPopulate<T>() method.

jkeon commented 1 year ago

This is now merged