You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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.
The text was updated successfully, but these errors were encountered:
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.
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.
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.
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.
The text was updated successfully, but these errors were encountered: