Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for entity references in command buffers #31

Open
richdog opened this issue Oct 9, 2023 · 0 comments
Open

Support for entity references in command buffers #31

richdog opened this issue Oct 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@richdog
Copy link
Contributor

richdog commented Oct 9, 2023

image

The above code shows the desired functionality, which is to be able to have an entity created via command buffer be set as a reference on another component on another entity via the same command buffer, before that entity has been created properly and has an ID assigned to it.

This is supported in Unity's ECS EntityCommandBuffer, but via some forbidden magic.
If anyone is willing to do something similar to support this functionality, here's some of what I gathered from going through the Unity code. Note that I'm referencing code in Entities 1.0.10.

I'm going to start with the managed version of this code, since they have different implementations for managed vs unmanaged components.

image
In line 4141 of EntityCommandBuffer of ECS is the AddManagedComponentData method (which is part of the PlaybackProcessor), which gets called when playing back the command buffer.
This method uses the TypeManager (a Unity Entities tool that keeps track of all the types) to check if the type has any references to entities.

image
If it does, it calls another method "FixUpComponent" (line 4499) to somehow modify the values of that type that reference the entity, using some otherworldly sorcery.

image

Unmanaged fixup takes a different approach, somehow keeping track of the component byte size (also using the TypeManager), an using that to find the components to "fix up" and put the correct entity in.

This does all feel like a very complicated solution to a very simple problem, but it would be a nice feature to have if there's a simpler solution.

@genaray genaray added the enhancement New feature or request label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants