- Home /
make a child always have its own scale?
Is there some way to code for a child object to retain its own original scale no matter what the scale/skew of the parent is? I don't know how to go about getting a specific scale for the object to refer to when parented to diffent objects with various scales.
Thanks
Answer by dannyskim · Nov 07, 2011 at 10:36 PM
I typically would recommend, if you do not have too many children to handle, that you write a simple update script that just follows the parent plus a designated offset so that it ignores rotation and scale altogether, instead of parenting inside the hierarchy. Yes, it adds more updates, but in the end it's just as easy as setting the localScale to the same every update as well.
I did wind up just putting localScale in the Udate function. I just have to watch how I scale the parent also, still. Thank you
Answer by rajat · Jul 25, 2013 at 10:40 AM
You can use this function whereever you are scaling the parent, it goes through the children and unparents them and then reparents them after scaling.
private void ChangeParentScale(Transform parent,Vector3 scale)
{
List<Transform> children= new List<Transform>();
foreach(Transform child in parent) {
child.parent = null;
children.Add(child);
}
parent.localScale = scale;
foreach(Transform child in children) child.parent = parent;
}
This is the method that worked for me, I just coded it differently.
Thanks :)
Answer by godwulf704 · Dec 15, 2014 at 05:59 AM
I found that just saying
transform.localScale = transform.localScale;
in Update() worked like a charm. I guess it just needed reminding haha.
Answer by yes-android-yes · Feb 25, 2015 at 05:59 AM
It looks crazy (in Update()): transform.localScale = transform.localScale; but it really works!!!
Answer by Indivisible · Mar 02, 2015 at 02:56 PM
Omg transform.localScale = transform.localScale; in Update () Worked perfectly. THANK YOU!