Hello,
I was wondering if there is any way to keep an object’s scale the same even after I assign its transform a different parent through a javascript. Thank you.
Sincerely,
Michael S. Lowe
Hello,
I was wondering if there is any way to keep an object’s scale the same even after I assign its transform a different parent through a javascript. Thank you.
Sincerely,
Michael S. Lowe
var localScale:Vector3 = transform.localScale;
transform.parent = someScaledObject.transform;
transform.localScale = localScale;
It will not work if two different parents have 2 different scales and the object gets assigned from one parent to the other.
“It will not work”
Well it will work it just might not do what you want. If you want the object to match the scale of its parent just set the localScale to Vector3.one after switching parents.
I see what the problem is. The problem wasn’t when I assigned the object a parent. I see that when an object gets assigned a parent, it automatically stays at the same scale. The problem happened when I used Instantiate to an object that wasn’t an actual root. The instantiated object uses a world scale according to the local scale of the leaf of the object that I am duplicating, so if the local scale of the object I am trying to duplicate is at Vector3(1,1,1) (being a branch of another object), the local scale of the duplicated object will also be Vector3(1,1,1) even though it is originally a root.
Interesting I didn’t know that!