- Home /
How to change scale an entiy ? ( ECS question )
setting localtoWorldComponent ( does not work )
setting Scale component gives error because no scale component exists
setting CompositeScale component gives error because no scale component exists
Comment
Best Answer
Answer by andrew-lukasik · Nov 25, 2020 at 05:13 PM
using Unity.Mathematics; using Unity.Transforms;
float3 newScale = new float3{ x=3f , y=3f , z=3f };
if( entityManager.HasComponent<LocalToWorld>(entity) )
{
var ltw = entityManager.GetComponentData<LocalToWorld>(entity);
entityManager.SetComponentData<LocalToWorld>( entity , new LocalToWorld{
Value = float4x4.TRS(
translation: ltw.Position ,
rotation: ltw.Rotation ,
scale: newScale
)
} );
}
else Debug.Log($"{entity} has no {nameof(LocalToWorld)} component");
Unity.Transforms.LocalToWorld
is more or less UnityEngine.Transform
equivalent. Scale
can be local (scalar) scale or world scale depending whenever entity has Parent
or not (the same is true for Translation
ie local position ).
Your answer
![](https://koobas.hobune.stream/wayback/20220613020518im_/https://answers.unity.com/themes/thub/images/avi.jpg)