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
3
Question by ChimpKing · Nov 28, 2010 at 06:16 AM · gameobjectsizeaxislength

How do I find the size of a gameObject?

How do I find the size of a gameObject? For example the length of x.

Comment
Add comment
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

3 Replies

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

Answer by Eric5h5 · Nov 28, 2010 at 06:41 AM

Use Mesh.bounds.size.

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
avatar image
11

Answer by Vunpac · Jul 01, 2014 at 12:37 PM

Well I came here looking for an objects unit size. I tried Mesh.size, but wasn't the objects unit size. Since it tells you the size of the mesh, not of the scaled mesh. So if you just multiply Mesh.size by transform.localScale, you will get the objects unit size.

Example: a plane in unity is 1, 1, 1 and it's unit (or mesh size) is 10, 0.00002(ish), 10. So if you scale the plans x by 5. It's unit size is 50 even AFTER scaling these are the sizes.

 mesh.bounds.size.x = 10
 transform.localScale.x = 5

so

 mesh.bounds.size.x * transform.localScale.x = 50
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 Pargee · Sep 20, 2016 at 11:10 PM 0
Share

This works great, thanks Vunpac!

 Vector3 objectSize = Vector3.Scale(transform.localScale, GetComponent().mesh.bounds.size);

avatar image Vunpac Pargee · Sep 21, 2016 at 03:42 AM 0
Share

glad to see it's still useful! :P

avatar image SimRuJ · Feb 16, 2021 at 02:22 PM 0
Share

I tried this on a plane that was instantiated with a prefab but getComponent<$$anonymous$$esh>() gave me an exception (no mesh component), that's why I just did: GetComponent<Collider>().bounds.size. The result was: (10.0, 10.0, 0.3) (I set the box collider to y=0.25!). Or, even easier if you don't want to use code: Just add a box collider and check it's size in the inspector. ;)

avatar image
0

Answer by fireDude67 · Nov 28, 2010 at 06:31 AM

It appears Transform.LossyScale does what you are looking for

Comment
Add comment · Show 2 · 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 Eric5h5 · Nov 28, 2010 at 06:42 AM 1
Share

lossyScale only tells you the scale of an object, nothing to do with the size.

avatar image fireDude67 · Nov 28, 2010 at 06:20 PM 0
Share

Oh. I thought the world scale of an object was in units...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Array.length edited using scripts 2 Answers

Check the length of a line renderer? 2 Answers

How to rotate the axis of a 3D GameObject 1 Answer

Destroy the first GameObject out of x fired 1 Answer

C# Variables Transform vs GameObject 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