understanding scale in unity

I’m new to working with unity and I’m working on a simple game. One issue I’ve been running into is scale and I am curious if anyone can offer some suggestions or clear some of this up for me.

The problem I am encountering is that I don’t see anyway to work in real units such as meters or feet. When I import a model from maya it seems to maintain it’s original scaling. Under scale for x,y,z in the inspector it says 3 - whatever that is. If I create a cube and set it’s scale to 3 it’s much smaller than the model So I assume the scale is just refering to the percentage of the original models size rather than an actual unit of measurment. So is there a way to do this, to reference actual dimensions?

In 3d graphics there is no absolute scale. There’s just units. If something is length 3 all that means is that it’s 3x longer than something of length 1.

3d packages which choose to use real world units are simply creating an illusion. Much like if you draft a plan and write “scale: 1 mm = 100 m” on it. This is only so if you believe it, and only accurate if you’re not looking at an enlarged or reduced copy.

The only place that real world scale actually exists in unity is in physics, where the default gravity constant is 9.8 meters per second per second acceleration. If that is true, then the built in cube is one meter on each side and each world unit is one meter. It is recommended that you use real world scale in your games at least at first because it simplifies things.

… oh wait. I just realized that both tonio and I misunderstood what you are asking. It sounds like you want to scale your models’ bounds sizes directly, instead of using the default relative scale. The inspector uses relative scale because it makes most sense, but you can set absolute size in a script.

// I am assuming that I have no rotation or parent
var newSize = Vector3;
function Start ()
{
    var size = renderer.material.bounds.size;
    var scale = Vector3(newSize.x / size.x, newSize.y / size.y, newSize.z / size.z);
    transform.localScale = scale;
}

exactly, I want to look at my thing and be able to see how big it is.

like: x units tall

rather than just

3x it’s original height

Here is a quicky that might help then:

  1. Create a folder called "Editor"in the project pane with Create>Folder

  2. Create a javascript in that folder with Create>JavaScript

  3. Open it and paste this in:

@MenuItem("GameObject/Print Selection Size_s")
static function PrintSelectionSize ()
{
	var first = true;
	var bounds : Bounds;
	var renderers = Selection.GetFiltered(Renderer, SelectionMode.Deep);
	for(var r : Renderer in renderers)
	{
		if(first)
		{
			bounds = r.bounds;	
		}	
		else
		{
			bounds.Encapsulate(r.bounds);	
		}
		first = false;
	}
	
	if(renderers.length == 1)
	{
		Debug.Log("Selected object's size in world units: " + bounds.size);
	}
	else if(renderers.length > 1)
	{
		Debug.Log("Selected objects' size in world units: " + bounds.size);
	}
	else
	{
		Debug.Log("No selected objects have a bounds");
	}
}

thanks for the code. Helpful… well… I have done as you’ve described… but I’m not finding the output. Does this display in the inspector, or in the output when the project is compiled?

no need to compile the game
in your menuitem
“GameObject” you will find “Print Selection Size” shortcut “S”

the printout is done to your console as an info

hope this helps, …

Good catch Yoggy :slight_smile:

Hmmm. Must be a 2.0 script.
AC

So this is wierd. In maya I specifically have my game object (skeeball machine) scaled to about 5.7 meters. Importing the same model in unity and it becomes about 570 units. Obviously I could scale down the model to 1/10th the size, but I must be doing somthing wrong here… Any ideas? (See attached .gifs)


54865--1994--$maya_183.gif

What does the Unity “import settings” window look like? I think with .fbx files the default setting is 0.01 scale, not sure what it is for Maya files.

looks like import settings option is grayed out and I can see no idication of why.

Have you clicked on the object whose settings you want to change? The import settings are per-object, not general.

–Eric

Thanks for bearing with me. I had been selecting only the object instance, not the object in the project folder. So here are the import settings. Doesn’t look like its set to scale anything.

I’d change “mesh scale factor” to 0.1, and then decide what you want to do with the other settings. I usually turn off “automatically calculate normals” and set “one material for every material in the scene”.

I cobbled together a quick and dirty custom inspector based shamelessly on the code for the menu item listed above. I prefer the information to be displayed this way. It pops up with the other inspectors every time you select a GameObject.

Thanks to forestjohnson like 3 years ago for the original code, which has been a huge help to me. 8)

// put me in /Assets/Editors/PrintSelectionSize.js

@CustomEditor(GameObject)
class PrintSelectionSize extends Editor {
	function OnInspectorGUI() {
		var first = true;
		var bounds : Bounds;
		var renderers = Selection.GetFiltered(Renderer, SelectionMode.Deep);
		
		for (var r : Renderer in renderers) {
			if (first) {
				bounds = r.bounds;
			} else {
				bounds.Encapsulate(r.bounds);
			}
			first = false;
		}
		
		EditorGUILayout.BeginHorizontal();
		EditorGUILayout.LabelField("World Dimensions", bounds.size.ToString());
		EditorGUILayout.EndHorizontal();
	}
}

i had my programmer rewrite this script to give me inches to get object size correct
working in 2017.x

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(GameObject))]
[ExecuteInEditMode]
[CanEditMultipleObjects]
public class PrintSelectionSize : Editor
{
    public override void OnInspectorGUI()
    {
        bool first = true;
        Bounds bounds = new Bounds();
        var renderers = Selection.GetFiltered<Renderer>(SelectionMode.Deep);

        foreach (Renderer r in renderers)
        {
            if (first)
            {
                bounds = r.bounds;
            }
            else
            {
                bounds.Encapsulate(r.bounds);
            }

            first = false;
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("World Dimensions (Unity)", bounds.size.ToString());
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("x:", (bounds.size.x * 39.37007874f).ToString() + "\"");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("y:", (bounds.size.y * 39.37007874f).ToString() + "\"");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("z:", (bounds.size.z * 39.37007874f).ToString() + "\"");
        EditorGUILayout.EndHorizontal();
    }
}

3319432–258245–PrintSelectionSize.cs (1.41 KB)