decline-cookies / anvil-unity-dots

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

Entity Lifecycle Management #158

Closed jkeon closed 1 year ago

jkeon commented 1 year ago

Adds the ability to nicely handle Spawning and Destroying Entitys.

What is the current behaviour?

You have to be diligent on where you define and populate your entities. Currently it's just easiest to do this on the main thread in some form of setup script but this doesn't scale to a larger project.

What is the new behaviour?

You define IEntitySpawnDefinitions which define the Components you need on your entity and then a function to populate them with data.

This gives us one place to define and populate and makes it easy to edit/change as the projects evolve.

The EntitySpawnSystem provides a one stop place to do any spawning. The system itself is flexible enough to be configured for any project's player loop or multi-world aspects.

You can:

All three have Prototype versions where instead of creating a new entity, an existing one is used to be cloned.

To balance this, the EntityDestroySystem is also present and performs the same functionality but for destroying entities.

The systems try to be as fast as possible by using Burst and enabling/disabling as needed but some things like SharedComponents will break burst so there is a non-burst path. Once we upgrade to Entities 1.0, we can ensure everything is bursted.

There are additional features and convenience aspects that would be nice to have but I'm going to wait on those until we need them (which might be really soon) and it keeps this PR shorter. These systems aren't fully feature complete, but they are valuable enough to make decent progress.

What issues does this resolve?

What PRs does this depend on?

Does this introduce a breaking change?

jkeon commented 1 year ago

Directory structure doesn't quite work with a bunch of destroy classes under "Spawning" but EntityDestroySystem not part of that. Suggest we take everything in the "Spawning" folder and put it under "Lifecycle" so it would be Lifecycle/

Job Interaction/
Spawner/
IEntitySpawnDefinition
EntitySpawnerSystem
EntityDestroySystem
UseCommandBufferSystemAttribute

Fixed.

I'm going to work on implementing your suggestion: https://github.com/decline-cookies/anvil-unity-dots/pull/158#discussion_r1095117677

I'll re-request the review when that's done.

Thanks for all the other comments, responded.

jkeon commented 1 year ago

@mbaker3 Good to re-review

jkeon commented 1 year ago

@mbaker3 Last comments addressed.