Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collider.bounds.extends.x returns local radius (SphereCollider) - Why?

Discussion in 'Scripting' started by Di_o, Nov 2, 2017.

  1. Di_o

    Di_o

    Joined:
    May 10, 2016
    Posts:
    62
    Hey ,

    today I updated my project to version 2017.2.0f3 (was working on 2017.1.1f1 before).

    This...

    Code (CSharp):
    1. offsetX = objectCollider.bounds.extents.x;
    ...used to return the bounds in world space of my SphereCollider, but now it only returns the radius of the component. The documentation says it should return the bounds in world space. Am I missing something, is this a bug or was this changed since the last patch? I'm a bit lost on this one.

    Maybe someone out there knows whats going on. :)

    Cheers
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Hi,

    I just took a quick glance at the documentation and source code surrounding the bounds and just from that, I can't see that any version intentionally returned the size of the bounds as its extents value. So while I'm not 100% sure, that this is not new behavior, it is definitely intended. See: Bounds.extents where it says
    I guess you might have been thinking of Bounds.size?
     
  3. Di_o

    Di_o

    Joined:
    May 10, 2016
    Posts:
    62

    I tried .extends and .size. The problem is not that the variable returns half or twice of what I need. I need the current radius in world space of this collider, since I'm rescaling the parent of it. The radius of my SphereCollider is always the same while the whole GameObject is rescaled. Every method that used to return the right value before the patch now just returns the radius that can be set in the inspecor for example.
     
  4. jeango

    jeango

    Joined:
    Dec 19, 2012
    Posts:
    109
    This is a bit old, but I had the same issue and solved it by multiplying the result by transform.lossyScale.x (global scale of the object)