Please check my code:
https://hastebin.com/ohovuqaqak.cpp
This is my workflow:
The artists create the prefabs as they used to (more or less), the code converts these prefabs in entity prefabs, using the code:
if (renderWorld != null)
{
prefabEntityID=
GameObjectConversionUtility.ConvertGameObjectHierarchy(prototypeGameObject.Result, renderWorld);
renderWorld.EntityManager.AddSharedComponentData(prefabEntityID, new UECSResourceGroup(prefabID));
renderWorld.EntityManager.AddComponent(prefabEntityID, ComponentType.ReadWrite<SveltoEGID>());
renderWorld.EntityManager.RemoveComponent<Translation>(prefabEntityID);
renderWorld.EntityManager.RemoveComponent<Rotation>(prefabEntityID);
renderWorld.EntityManager.RemoveComponent<NonUniformScale>(prefabEntityID);
}
Anytime I need a new entity, I then instantiate the prefab using this code:
var entity = manager.Instantiate(prefabEntityID);
In the JobComponentSystem, I iterate all the entities with the following components:
typeof(LocalToWorld), typeof(SveltoEGID), typeof(UECSResourceGroup)
SveltoEGID is currently used in this context only to mark the root prefabs, as I want to iterate only the root (currently I didn’t find another way to identify roots of gameobject hierarchies).
I remove the Translation,Rotation and NonUniformScale from the prefab for the purpose to disable all the systems that write in the LocalToWorld matrix, as deducted from Joachim advices.
I store in the _instanceData system field, all the entities grouped by prefabID (resourceStructResourceId). If there entities, then I schedule a job to apply the transformation matrix to this set of entities. I set a group filter to be sure that I am going to iterate only the entities with that resourceID.
var uecsResourceGroup = new UECSResourceGroup(resourceStructResourceId); is a SCD that I use only to group the UECS entities by resource ID
As result I expect that all the roots of the instances generated by the prefabID gameobjects will be iterated and the LocalToWorld set.
I also expect that the children of these roots are transformed by this matrix, but this is NOT happening and it’s my current problem I seed advice of.
as side note “DO_THIS_ONCE_THE_SCD_WORKS” is currently disabled because of the problem that for some specific gameobjects the SCD is not working, generating a chunk for each entity as opposite of a chunk for each prefabid
Note: please check the way I am scheduling the jobs too. I am not sure it’s the optimal way. These jobs should be scheduled in parallel and not in serial, plus the entity debugger shows the entities touched by the last job scheduled and not all of them