decline-cookies / anvil-unity-dots

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

Custom Entity Migration #232

Closed jkeon closed 1 year ago

jkeon commented 1 year ago

Unity will automatically remap Entity references on Components and in DynamicBuffers when Entities move from one World to another.

Entities that exist in TaskDrivers or EntityPersistentData however will not.

This PR gives functionality to provide a framework for allowing anything to be remapped and implements it for TaskDrivers and EntityPersistentData

What is the current behaviour?

No way to provide custom remapping.

What is the new behaviour?

Framework

Anything can implement the IMigrationObserver and register with the WorldEntityMigrationSystem to receive a notification when Entities have migrated to a new World.

The callback will provide the necessary information to perform the custom logic to remap Entity references.

MigrationUtil provides the functionality to actually do the remapping via RegisterTypeForEntityPatching and then the call to PatchEntityReferences.

All changes to the world should happen through WorldEntityMigrationSystem.MigrateTo. If you use the EntityManager.MoveEntitiesFrom vanilla function, we won't know and custom migration won't happen.

TaskDrivers and EntityPersistentData

I've handled both of these systems to automatically register their types and patch references. Everything is jobified so that we can use Burst and in practice ends up being pretty quick.

Tag-Alongs

What's Next

What issues does this resolve?

What PRs does this depend on?

Does this introduce a breaking change?

jkeon commented 1 year ago

@mbaker3 Ready for re-review.

Also contains changing the name of the Task Driver System to the outside to be System and the internal one to be TaskDriverSystem instead of the flip-flop it was before.

mbaker3 commented 1 year ago

All addressed. Some discussions to sort out but this is looking good!