boundingBoxCamera = GetSingletonEntity<BoundingBoxCamera>();
localToWorld = entityManager.GetComponentData<LocalToWorld>(boundingBoxCamera);
entityManager.SetComponentData<Translation>(boundingBoxCamera, new Translation { Value = new float3(3f, 2f, 1f) });
entityManager.SetComponentData<LocalToWorld>(boundingBoxCamera, new LocalToWorld
{
Value = float4x4.TRS(
translation: new float3(0f, SC_Initialize.height / 2, 0f),
rotation: localToWorld.Rotation,
scale: new float3(SC_Initialize.width + 10f, SC_Initialize.height + 10f, SC_Initialize.width + 10f)
)
});
In this case nothing set by SetComponentData<LocalToWorld> works, Entity has the same Rotation and Scale as before, and Translation is only changed by SetComponentData<Translation>.
Local to world is overriten internally by DOTS systems.
If you use translation, rotation components, there is also scale/none unifor scale components.
Do not try to change local to world manually. Won’t work, unless you disable Unity system.
boundingBoxCamera = GetSingletonEntity<BoundingBoxCamera>();
entityManager.SetComponentData<Translation>(boundingBoxCamera, new Translation { Value = new float3(0f, SC_Initialize.height / 2, 0f) });
entityManager.AddComponent<NonUniformScale>(boundingBoxCamera);
entityManager.SetComponentData<NonUniformScale>(boundingBoxCamera, new NonUniformScale { Value = new float3(SC_Initialize.width + 10f, SC_Initialize.height + 10f, SC_Initialize.width + 10f) });
Does the trick.
I have seen an example of code somewhere with writing to LocalToWorld directly, and that seems to be wrong, as you have mentioned.
The problem was that my Entity somehow had no NonUniformScale component, even though it had non-uniform scale. It seems that this component is not added by default, and you have to add it if you plan to change the scale.
By the way, when I did try to change this component (without adding it first) together with LocalToWorld, I’ve got A component with type:Unity.Transforms.NonUniformScale has not been added to the entity error, but the changes to LocalToWorld had been applied. And that was strange: Entity had the previous Translation, no NonUniformScale component, but in fact was rendered according to different values from LocalToWorld matrix.
I just noticed that you cant change LocalToWorld scale value in the moment that you create an entity. my solution to this was :
1- create entities with a system
2- reach those entities with another system and then create a LocalToWorld value by urself with help of Matrix4x4.TRS(position,rotation,Scale);
there you can manipulate the Scale as float3 with what value you want . (you can deform the entity)
new LocalToWorld { value = Matrix4x4.TRS(Get Position of entity, Get rotation Of entity, Use New Scale that you want)}