Cleanup GameObject Scale in hierarchy?

Hi,
I have a large scene with several thousand GameObject that are arranged in a hierarchy (Region, etc.). Over time, with lots of changes and moving objects and groups of objects around, many levels of that hierarchy have been scaled. The numbers range from 0.00x to several hundred and they often alternate: Object has a scale (55, 200, 160), its child has a scale (0.01, 0.003, 0.004), and so on.

So my question is: is there an easy way (or a way at all) to clean that up?

Edit: thanks for the response NorthStar79, here is how I adapted it:

private void CleanUpScales()
        {
            foreach (Transform child in self.transform)
            {
                CleanUpScale(child, 1, 1, 1);
            }
        }

        private void CleanUpScale(Transform transform, float multiplicationX,
                float multiplicationY, float multiplicationZ)
        {
            var localScale = transform.localScale;
            var localPosition = transform.localPosition;

            transform.localPosition = new Vector3(
                    localPosition.x * multiplicationX,
                    localPosition.y * multiplicationY,
                    localPosition.z * multiplicationZ
            );

            multiplicationX *= localScale.x;
            multiplicationY *= localScale.y;
            multiplicationZ *= localScale.z;

            if (transform.GetComponent<Renderer>() == null)
            {
                transform.localScale = new Vector3(1, 1, 1);

                foreach (Transform child in transform)
                {
                    CleanUpScale(child, multiplicationX,
                            multiplicationY, multiplicationZ);
                }
            }
            else
            {
                transform.localScale = new Vector3(
                        multiplicationX,
                        multiplicationY,
                        multiplicationZ
                );
            }
        }

as far as I know, scale property of a game object cannot convert to global from locale but still, you can write a workaround for that. I will explain how you can create your own “scale normalizer” but please note that this method may break your object positions if they have unusual pivot points but I guess we will never know unless we try it :slight_smile:

okay, first you need to be familiar with recursive functions. please check it out before reading further than come at this point again.

you can call every game object and their children objects by their transforms recursively.

lets assume you have an onject called “A” and its scale is : 2-2-2
and “A” has 2 child named “A1” at scale 0.5-0.5-0.5 and “A2” at scale 1-1-1

first create a variable that stores a multiplication value.

first call “A” then divide its x scale to 1 and store it.

muliplication =  1/A.transfom.x;

than change “A” x scale to 1

A.transform.scale = new Vector3(1,A.transform.scale.y,A.transform.scale.z);

after that Get “A1” and modify its scale

float temp = multiplication;
multiplication *= A1.transfom.scale.x;
A1.transform.scale = new Vector3(A1.transfom.scale.x*temp,A1.transfom.scale.y,A1.transfom.scale.z);

do it for every child of “A1” and for their childs too until you hit the very bottom.

then come back to “A2” and repeat.

and also do same procces for also scale.y and scale.z

I wish I could help more but this is a complicated task and I can not affort any more time for writing an answer. II hope this will lead you to a direction. good luck.