Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Namerian · Mar 07, 2018 at 10:58 AM · editortransformscenehierarchyscaling

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
                 );
             }
         }


Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FuzzyLogic · Mar 07, 2018 at 11:40 AM 0
Share

Are the objects displayed correctly?

What would you want to do? Scale the parent down by 10 and scale the child up by 10? So that the parent is <5.5, 20.0, 16.0> and the child is <1.0, 0.3, 0.4>?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by NorthStar79 · Mar 07, 2018 at 11:38 AM

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 :)

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

125 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Some changes in hierarcy gone after i run play mode ? 0 Answers

Overwrite the inspector window on Scene Asset heading chosen in the hierarchy window 0 Answers

Getting the selected scenes in hierarchy view? 1 Answer

Cannot close/unload a scene that is open in editor during playmode (using C# code)? 3 Answers

Object changes position/rotation, when moved (in/out of parent) in the heirarchy in the editor! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges