- Home /

# GameObject Scale as World Coordinates (Units)?

Good evening,

I've got a quiet annoying problem..

I need to get the scale of a GameObject, unlike transform.localScale which gives me (1, 1, 1) as the default scale of my model, I need to get the scale as coordinates (or the coordinate system's units).

I hope you understand what I mean.

It sounds very simple but I can't find any solution.

Thank you for each answer!

Mike

### People who like this

**Answer** by aldonaletto
·
Jun 16, 2013 at 06:40 PM

I suppose that you want to get the actual *dimensions* of the object in world units - am I right? If so, you could get the collider, renderer or mesh bounds: the bounding box is an axis aligned box that fully encloses the object, and is expressed in world units. There's a problem, however: since it's axis aligned, a long object may appear bigger than it actually is if there's any rotation. If you want a more precise evaluation of actual dimensions, you must get the mesh vertices, multiply by the scale and find the max and min of each axis - something like this:

```
function GetDimensions(obj: GameObject): Vector3 {
var min: Vector3 = Vector3.one * Mathf.Infinity;
var max: Vector3 = Vector3.one * Mathf.NegativeInfinity;
var mesh: Mesh = obj.GetComponent(MeshFilter).mesh;
for (var vert: Vector3 in mesh.vertices){
min = Vector3.Min(vert);
max = Vector3.Max(vert);
}
// the size is max-min multiplied by the object scale:
return Vector3.Scale(max-min, obj.transform.localScale);
}
```

I get a no overload error for the Vector3.Min/Max. apparently they take two arguments. EDIT: put in vector3.zero as second argument for both. Seems to fine now. Thanks!

If you could instead explain why this works, I would be really grateful! :)

Actually the lines should be

```
min = Vector3.Min(min, vert);
max = Vector3.Max(max, vert);
```

All those two lines does is to find the lowest and highest x / y / z value of all vertices.

So for example:

```
var min = Vector3.Min(new Vector3(10,2,-5), new Vector3(7,3,1));
var max = Vector3.Max(new Vector3(10,2,-5), new Vector3(7,3,1));
// min will be (7,2,-5) and max will be (10,3,1)
```

Since we store the result in min and max and use that variable again min will end up with the smallest values and max with the largest.

Actually there's no need for this method since mesh.bounds will return the same thing (just without the scaling at the end). Mesh.bounds is axis-aligned in local space while Renderer.bounds is axis-aligned in worldspace.

[EDIT]

transform.bounds gives you the global size, axis oriented. mesh.bounds gives you the local size of the mesh, which returns the same!. Instead of doing all that, which is a lot slower, depending on the size of the model.

Fixed C# Version. Vertices are expressed locally to the object so this should work.

```
private Vector3 GetDimensions(GameObject obj)
{
Vector3 min = Vector3.one * Mathf.Infinity;
Vector3 max = Vector3.one * Mathf.NegativeInfinity;
Mesh mesh = obj.GetComponent<MeshFilter>().mesh;
for (int i = 0; i < mesh.vertices.Length; i++)
{
Vector3 vert = mesh.vertices[i];
min = Vector3.Min(min, vert);
max = Vector3.Max(max, vert);
}
// the size is max-min multiplied by the object scale:
return Vector3.Scale(max - min, obj.transform.localScale);
}
```

### Your answer

### 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.