• 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
2
Question by runningTurtle · Jul 02, 2015 at 08:03 AM · bounds

How does bounds.Expand() work ?

I'm a bit confused as to how bounds.Expand() works:

     Bounds bounds = collider.bounds;             
     Debug.Log("Before " + bounds.min.x);       // -0.5
     Debug.Log("Before " + bounds.size);        // (1.0, 1.0, 0.0) 

     bounds.Expand(0.015f * -2.0f);

     Debug.Log("After " + bounds.min.x);        // -0.485
     Debug.Log("After " + bounds.size);         // (1.0, 1.0, 0.0)

The documentation says "Expand the bounds by increasing its size by amount along each side.", but the snippet above seems to show that size is not affected and only bounds.min is changed ?

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

1 Reply

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

Answer by revolute · Jul 02, 2015 at 08:19 AM

All of them are changed. Bounds.ToString() returns the floating numbers rounded to the nearest int.

Comment
Add comment · Show 4 · 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 revolute · Jul 02, 2015 at 08:20 AM 0
Share

If you try bounds.size.x ins$$anonymous$$d of bounds.size, you will see that it has changed. I'm not sure why Unity does that way, but thats how ToString is extended internally.

avatar image Darkgaze · Jun 20, 2019 at 12:15 PM 0
Share

NOTE: If you are running a bounds.Expand() on a collider or terrainData bounds, it will not change the original one, because it is read-only, so it will return a copy and the change will not take effect on the original.

avatar image Bunny83 Darkgaze · Jun 20, 2019 at 12:30 PM 1
Share

Of course since Bounds is a struct so changes on a bounds can not have any effect on the bounds of the collider. Also as you have mentioned there is no way to set the bounds of primitive colliders. You can however set the bounds of a $$anonymous$$esh if required.


ps: The managed portion of the UnityEngine.dll is available for reference only on github. You are not allowed to copy or redistribute the code posted there. It's just for reference. As we can see the Expand method does just add the given amount equally to the extents.

avatar image NickVst Bunny83 · Oct 14, 2019 at 11:35 PM 0
Share

This seems unintentionally misleading on Unity's part. The documentation states that bounds.Expand() "increases its size by amount on each side", but from this code sample it seems that it increases its side on each side by half of the amount given, ins$$anonymous$$d increasing the size along the axes by amount.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 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

Related Questions

Get position of the centre of each grid tile 1 Answer

How can I consistently get the rectangle bounds around a mesh? 2 Answers

Getting Screen Bounds 1 Answer

Get right or left Vector2/3 out of renderer.bounds 0 Answers

Moving object next to another object. 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