Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Discussion Help me understand: Why does Unity not have object sizes? (Width/Height/Depth)

Discussion in 'Getting Started' started by Rejutka, Aug 11, 2022.

  1. Rejutka

    Rejutka

    Joined:
    Feb 19, 2017
    Posts:
    17
    Inside the Transform component, there is a "position" and a "scale". The latter basically applies a multiplier to the object size, whatever that is.
    The former allows you to position the object.

    But there is no way to know how big or small an object is? Not even for the built-in primitives.
    If I create, for example, a cube and want to stack a cylinder (scaled to 0.35) on top of it, I have to guess/visually check if they're really stacked upon each other.
    (I chose 0.35 because it's a random value. I know by now that a cylinder is 2 units high and a cube 1 unit. So I could calculate the position for 0.5 height.)


    Unity thrives - there's tons of great games made with it, so obviously this cannot be the huge obstacle for others that it is for me.
    Tutorials never even mention it, as if the issue didn't exist - even tutorials made for beginners.

    So where are my circuits crossed, what am I not seeing that everyone else instinctive knows, that is so obvious that no one mentions it?
    It can't be that everyone just "guesstimates" the correct positioning, or find it by trial and error. Right?
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    819
    I think probably because there are many different kinds of objects and many ways to define what an object's size is.

    In the case of primitives and any other object with a Mesh, you can use Mesh.bounds to get the information I believe you're looking for:

    https://docs.unity3d.com/ScriptReference/Mesh-bounds.html
     
    Rejutka and Ryiah like this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    Like @flashframe mentioned you can check the size through the mesh. The reason it's not tied to the GameObject is because that's not the role of the GO for reasons including because it's possible to have more than one size. You have the visible mesh size but you can also have the size of each collider attached to the GO.

    https://docs.unity3d.com/ScriptReference/Collider-bounds.html
     
    Rejutka likes this.
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,860
    I've rarely needed to know this, but since you now know that most primitives are 1 unit in each dimension (except cylinders, which are 2 units high), you just multiply that by the transform.lossyScale to get its current size.