Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Nanako · May 21, 2015 at 06:28 PM · transformscale

How can i get the total scale of an object?

So i have a game object which is buried an arbitrary number of layers deep in the hierarchy. And every parent object above it might have a different localscale value.

Is there any better way than recursing up the hierarchy multiplying them all, to find this objects absolute/total scaling value ?

Comment
Add comment · Show 2
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 Michael-Glen-Montague · May 21, 2015 at 06:33 PM 1
Share

What about transform.lossyScale?

avatar image Nanako · May 21, 2015 at 08:39 PM 1
Share

sounds good. But imperfect.

How can i do it perfectly using a transform matrix? with this particular bit of code im doing, accuracy is most important, and i have a long time to calculate it. like, it wouldn't matter if this operation took several seconds.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jonesy19 · May 21, 2015 at 08:59 PM

I have run into this same issue, and the only way I have been able to do it is (as you said) to recursively go up the tree and multiply the scales...I've looked around a lot for an answer and, unfortunately, that's the only way I've been able to do it. :(

Comment
Add comment · Show 3 · 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
avatar image Nanako · May 21, 2015 at 10:38 PM 0
Share

but isn't this exactly what transform matrices are for? have you tried working with that?

avatar image Nanako · May 21, 2015 at 10:39 PM 0
Share

failing that, if you got it working do you maybe have a code snippet i could use? ^-^

avatar image Jonesy19 · May 24, 2015 at 01:21 PM 1
Share

Sure, I didn't have it offhand, but I quickly threw this together... This is recursive, which is unfortunate, but I just tested it out to three layers deep and it gets the scale exactly.

 void deter$$anonymous$$eScale()
     {
 
         Vector3 tempScale = new Vector3(1, 1, 1);
         Transform t = this.transform;
         while (t != null)
         {
             tempScale = new Vector3(tempScale.x * t.localScale.x, tempScale.y * t.localScale.y, tempScale.z * t.localScale.z);
             t = t.parent;
         }
         totalScale = tempScale;
     }







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

20 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

Related Questions

How to smooth transform scaling with 2d sprite 1 Answer

TextMeshPro Height 0 Answers

Gradually scale platform? 4 Answers

Can the insides of a gameObject affect its transform? 0 Answers

GameObject Scale as World Coordinates (Units)? 1 Answer


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