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 Jihoon Lee · Jun 19, 2013 at 01:49 AM · vector3boundsassignment

Issue with bounds.SetMinMax assigning incorrectly.

Hello everyone! I hope your month is going well!

Currently I've run into this issue that I'm trying to work out. All the actual values themselves have been checked and rechecked, so it's not a careless assignment error on my part.

Given the following information:

 GameObject go = new GameObject();
 BoxCollider bc = go.AddComponent("BoxCollider") as BoxCollider;
     
 Vector3 temp1 = new Vector3(nodeList[iterator].min.x, nodeList[iterator].min.y, nodeList[iterator].min.z);
 
 Vector3 temp2 = new Vector3(nodeList[iterator].max.x, nodeList[iterator].max.y, nodeList[iterator].max.z);
     
 bc.bounds.SetMinMax(temp1, temp2);
 bc.center = new Vector3(nodeList[iterator].center.x, nodeList[iterator].center.y, nodeList[iterator].center.z);

Now, from here, if I print out the values of "nodeList[iterator].center.x" and "bc.center.x", they are identical.

If I print out the values of "nodeList[iterator].min.x" and "temp1.x" they are identical.

However... printing out "temp1.x" and "bc.bounds.min.x" gives me two different values! For instance, temp1.x might report as 8.333334, and bc.bounds.min.x reports as 8.25.

The next set might print out as temp1.x being 7.5 with bc.bounds.min.x being 7.416667.

I just cannot seem to figure out why there is this assignment issue happening with the bounds.SetMinMax(). The values are absolutely identical in all ways, and assignment works in everywhere else, but just specifically when assigning the value to the bounds.SetMinMax() it gives a clearly different value than what I am assigning to it.

Has anyone else ran into this problem, or know of why Unity's bounds.SetMinMax() function is doing this? Thanks a lot!

UPDATE: I have tried doing the SetMinMax() assignment directly through the GameObject itself that the BoxCollider is attached to, and this is having the same issue. GameObject.Collider.Bounds.SetMinMax(temp1, temp2), then, afterwards, GameObject.Collider.Bounds.Min.x IS NOT temp1.x -- as I can't actually get into Unity to see how the SetMinMax() function works and does assignment to the object, I can't decide whether this is a bug in Unity's engine, or not. If it is a bug, I'm not sure if I should report it here or other places.

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 intrepidis · Dec 30, 2014 at 10:33 PM 0
Share

I have a similar problem. I have created a Bounds object as a member field to a class and declared it readonly (this is in C#). I cannot change the values of the Bounds object at all. If I remove the readonly declaration I can then set the values of the Bounds object!?! Clearly Unity does some sort of funky transformations to the CIL that cause this strange behaviour.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Inhuman Games · Jul 17, 2015 at 02:47 PM

Bounds is a struct.

In C#, structs are passed around by value. Collider.bounds will return a copy of the real bounds. Any changes to the copy will be not reflected in the original Collider.

Unforunately, Collider's bounds property only has a getter, not a setter. This means you can't change the copy and give it back to the collider.

The solution is to use BoxCollider's set properties:

         BoxCollider boxCollider = GetComponent<BoxCollider>();

         Bounds bounds = new Bounds();
         bounds.SetMinMax(temp1, temp2);

         boxCollider.center = bounds.center;
         boxCollider.size = 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

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

16 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

Related Questions

Find a Touch in the BoxCollider 1 Answer

best way to check if a Vector3 point is within any of multiple colliders 1 Answer

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

Is there a way to check for a line as opposed to a Vector3 point with Bounds.Contains? 1 Answer

Calculate bounds of a box including rotation 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