- Home /
The question is answered, right answer was accepted
Parent-child scaling problem (Solved)
So I have child objects that are essentially the same model and size of the parent, just different textures.
My problem is, when I instantiate a child from code, it uses its scale values as absolutes, BUT when I drag a child into the scene, it uses the scale relative to the parent ( (1,1,1) would be the same as parent ).
So if I have an object scaled x2, y10, z10, and the child with the exact same values, spawning the child with code gets be an object the size of (2,10,10), but dragging the child into the scene gets me an object the size of (4, 100, 100) and I have to manually reset the values.
The best way to fix this would be to make the code also use relative scaling, so I could just set the child's scale to (1,1,1) everywhere. How would I go about doing this?
Used
child.localScale = parent.transform.localScale;
after the instantiation, as that was what I needed. Now my objects drag and instantiate into the scene all the same size. Thank you for getting me on the right track! No clue how I managed to miss that method...
Answer by Quaker_SDR · Jun 24, 2013 at 12:32 PM
use transform.LossyScale to assign it back to original size.
Follow this Question
Related Questions
I have an error, script should check for null or not destroy game objects 2 Answers
[C#] An error occurs when trying to set a child to my GameObject in script. Why? 0 Answers
Calling an Audio Source on one game object from a script on another game object..? 1 Answer
"Center On Children" programmatically 1 Answer
Destroying childs and Instantiate [C#] 0 Answers