1
\$\begingroup\$

I'm just learning the new Unity ecs and trying to change the size (scale) of an entity. Everything works fine, I can change the rotation, the position but not the scale.

I'm wondering why. I did various tutorials, I tried Scale, NonUniformScale, LocalToWorld, CompositScale but nothing works. Maybe some of the methods are deprecated.

Here is what I have tried so far.

I have multiple prefabs (planes) which are spawned correctly and each of them having a transform component.

enter image description here

Now I want to change the scaling of all the planes. For that I use a JobComponentSystem. In the following pice of code the rotation works fine, but not the scaling.

I tried LocalToWorld.

public void Execute(ref Rotation rotation, ref LocalToWorld scale) {
            rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
            scale.Value = float4x4.Scale(2, 4, 5);
        }

I tried NonUniformScale

public void Execute(ref Rotation rotation, ref NonUniformScale scale) {
            rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
            scale.Value = new float3(2, 1, 4);
        }

I tried Scale.

public void Execute(ref Rotation rotation, ref Scale scale) {
            rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
            scale.Value = 5;
        }

None of these is working. What did I wrong (the scale just stays at 10,1,10) or what is the current propper way of doing that?

\$\endgroup\$
0
\$\begingroup\$
public void Execute(ref Rotation rotation, ref CompositeScale scale) {
        rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
        scale.Value = float4x4.Scale(1, 2, 1);
    }
\$\endgroup\$
1
  • 4
    \$\begingroup\$ Welcome to Game Development Stack Exchange. Good answers on this website should not just give a solution but also teach the reader the knowledge to understand the solution. Can you tell us more about how your code is different from those posted in the question, why exactly that change solves the issue and how one would know that this is the correct way to do it? \$\endgroup\$ – Philipp Feb 19 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.