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

ModelImporter.globalScale

Discussion in 'Scripting' started by Alex_TNT, Oct 2, 2015.

  1. Alex_TNT

    Alex_TNT

    Joined:
    Dec 26, 2011
    Posts:
    231
    Since isFileScaleUsed is Read-only, this script detects the File Scale and Recalculates the Scale Factor( Global Scale) accordingly.

    Code (csharp):
    1. using UnityEditor;
    2.  
    3.  
    4. public class FBXScaleFix : AssetPostprocessor
    5. {
    6.   public void OnPreprocessModel()
    7.   {
    8.   ModelImporter modelImporter = (ModelImporter)assetImporter;
    9.   modelImporter.globalScale = 1.0f / modelImporter.fileScale;
    10.   UnityEngine.Debug.Log("Import file scale: " + modelImporter.fileScale + ", global scale: " + modelImporter.globalScale);
    11.  
    12.   }
    13. }
    14.  
    Problem is that OnPreprocessModel fileScale is detected as 1 but it shows after 0.01 ( example number )

    But if you change any setting inside inspector the object Scale Factor( Global Scale) scales to normal value, in this example 100

    This doesn't work either
    Code (csharp):
    1. public void OnPostprocessModel()
    2. {
    3.    ModelImporter modelImporter = (ModelImporter)assetImporter;
    4.    importer.importMaterials = false;
    5.  
    6. }
    Does anyone know a solution to this?