lossyScale

So apparently lossyScale is read only (logged as a bug)

I am trying to give children of a scale parent world scale of 1,1,1.

How would I do that ?

Edit: I use localScale in many places, so I know that works. You could read the lossyScale and use that to figure out how to set the localScale properly.

I don’t know why, but setting lossyScale never seemed to work for me either. It never gave me an error message, it just never changed.

If you’re trying to set lossyScale like this:

transform.lossyScale.x = 1;
transform.lossyScale.y = 1;
transform.lossyScale.z = 1;

Then for the lossyScale part the value is determined and saved in a copy. Setting the x/y/z then does not save it to the original but to the copy, which is discarded afterwards. Since the operation succeeds, there’s no error, but Unity 2 should show a warning (assignment to temporary).

If you’d instead try to set the lossyScale directly:

transform.lossyScale = Vector3.one;

You get an error that lossyScale is read-only.

As for setting scale in world-space. If none of the children have any rotation, then it’s not very hard. Just loop through all parents and multiply the individual scale compoments to get the factor to convert from local- to world-space.

workaround :
buffer the parent
unparent
local scale to one
re parent to the buffer

Your workaround helped me. Thank you!

Lossyscale being read-only isn’t a bug, it’s by design. It’s actually the reason it’s named “lossyScale” and not simply “scale”.

Consider this hierarchy:
Parent (rotated 45,0,0)
Child (scaled 1,.25,1)
Grandchild

Now, let’s say I, the coder, set the value of Grandchild.lossyScale to (2,1,1). What should the engine do?

There is no correct answer. Positions and rotations can just be reverse-transformed all the way up the chain, but scale? There’s nothing the engine can do to make any value of lossyScale I give it make sense. The mere existence of rotation screws everything up. If all the parents of the object are unrotated, or rotated only in perfect 90 degree increments, then it can do something. But there’s no way to guarantee that is the case.

Here’s an exercise you can do to try it

  1. Create the hierarchy as described above
  2. Create a cube
  3. Make the cube a child of “Grandchild”. Watch it skew!
  4. Now the fun part: Try and manipulate the transform values of the cube to make it look like a cube again. You can’t do it. Neither can Unity.

If you don’t want children to have their scale affected by their parents, then don’t make them children. It’s as simple as that.