ModelImporter.globalScale problem

Anyone know why this won’t work? It used to work in Unity 2.x but it is just not applying any scaling to the models now (Unity 3.1). I have tried it on FBX and Maya files. I have to go edit “Scale Factor” manually for each to set scale.

public class EditorCommon : ScriptableObject 
{
....
....
static void SelectedChangeImportScale(float scale)
{
	foreach (Object obj in Selection.objects)
	{
		string path = AssetDatabase.GetAssetPath(obj);
		ModelImporter modelImporter = ModelImporter.GetAtPath(path) as ModelImporter;
		if (modelImporter)
		{
			modelImporter.globalScale = scale;
			AssetDatabase.ImportAsset(path);
		}
	}
}
....
....

What happens? Does it actually execute “modelImporter.globalScale = scale;”? Do you get “Aplly your changes dialog”?

Yup, the “Unapplied import settings” dialog comes up and I press “Apply”. Like I mentioned, this code used to work (on older Unity while I was still making iPhone games). There is also no error messages on the console.

I chose for example a value of 10 for the scale but after pressing Apply I can see the scale factor is still 0.5 (a value I manually entered, but this also happens for any newly imported models - he 0.01 ones), and when I drag the model into the scene it is obvious that the scale did not change.

After further testing I think I know what is going on.

I select 3 of the models (in Project panel) which I would like to set the scale for (via the script in first post). Lets call them gun01.fbx, gun02.fbx an gun03.fbx. After selecting these, gun1’s properties are showing up in the Inspector.

I then select my custom menu option to set scale to “1” and a dialog pops up (Unapplied import settings), BUT, only for gun01.fbx.
It is when I press “Apply” on that dialog that gun01.fbx scale is set back to 0.01 while the otehr 2 models’ scale was set correctly to “1”. I had to click on “Revert” on the dialog to get scale to “1” for gun01.fbx too.

It seems that the editor thinks I’ve manually changed the scale in inspector to 0.01 again and asks if settings should be applied, so if I press Apply its set to 0.01 while Revert will keep what my script set it to.

This was tested on 3.1.0f4

Yes, we have this bug, but we haven’t decided what to do with it. As a short temp solution: press revert…

It’s important to clarify that after these changes you need to reimport the assets, otherwise the changes are just in the interface !!
This could (and / or should) be in the documentation.

Great forum !!!