I have quite a simple setup. - Solved.
Imagine you have a parent GameObject at -48,0,-5with some rotation and scale. I’ve added it in ECS at runtime.
The parent has:
typeof(LocalToWorld),
typeof(LocalTransform),
typeof(MeshLODGroupComponent),
Then I set it’s position:
var localTransform = new LocalTransform{Position = transform.position, Rotation = transform.rotation, Scale = 1};
entityManager.SetComponentData(entity, localTransform);
The child is at position 0.something, 0.something, 0.something and has:
typeof(LocalTransform),
typeof(Parent),
typeof(RenderMesh),
typeof(PostTransformMatrix),
typeof(RenderBounds),
typeof(MeshLODComponent));
foreach (var data in renderData){
var description = new RenderMeshDescription(ShadowCastingMode.Off, layer: 12, receiveShadows: false);
var renderMeshArray = new RenderMeshArray(new[ ] {data.material}, new[ ] {data.mesh});
SetupEntities(data.entity, parent, 1);
}
In SetupEntities I do:
entityManagerSetComponentData(e, new PostTransformMatrix {Value = 1f}); // Solved this is not identity.
entityManager.SetComponentData(e, new Parent {Value = entity});
entityManager.AddComponentData(e, new LocalToWorld());
entityManager.SetComponentData(e, new LocalTransform { Position = localMatrix.position, Rotation = localMatrix.rotation, Scale = 1f}); // All positions are local from the gameObject transform 0.03, 0.2, -0.3
entityManager.SetComponentData(e, new MeshLODComponent {Group = entity, LODMask = lodMask, ParentGroup = entity});
RenderMeshUtility.AddComponents(
e,
entityManager,
description,
renderMeshArray,
MaterialMeshInfo.FromRenderMeshArrayIndices(0, 0, (sbyte) data.meshIndex));
The parent instantiates valid:
However the child looks like this:
The child does not render correctly due LocalToWorld.
If I manually modify it to:
And it worked, I don’t know what I miss here or what is the problem
Any idea if I should call something to actualize the value after changing it?