Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Importing objects at 1.0 scale, how to improve this script?

Discussion in 'Scripting' started by Nanako, Jan 13, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    i hate unity's importing stuff at 0.01 scale, it's just plain wrong. i flat out refuse to make things at 100x size

    I fixed it by using this little script

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System;
    4. public class CustomImportSettings : AssetPostprocessor
    5. {
    6.     public const float importScale= 1.0f;
    7.     void OnPreprocessModel()
    8.     {
    9.         ModelImporter importer = assetImporter as ModelImporter;
    10.         importer.globalScale = importScale;
    11.     }
    12. }
    It works, but it's notperfect

    For one, it disables the import scale option entirely, and basically hardcodes it to 1.0
    this is fine for anything i make but is problematic forr assets i purchase or otherwqise aquire

    Secondly, i have a vague suspicion it might cause issues. this just seems like a sloppy way of doing things.

    ideally i'd like it to automatically set that field to 1.0, but still allow me to change it, if possible.

    is there any way to improve the script to accomplish that? is there a better way to do this?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Change to postprocess
    Code (CSharp):
    1.     void OnPostprocessModel ( GameObject g ) {
    2.         ModelImporter importer = assetImporter as ModelImporter;
    3.         importer.globalScale = 1;
    4.     }
    5.  
    Although the number in the import options will always revert to 1, it does actually appear to apply the newly typed-in value to the mesh

    Edit: Nah wait, now it doesn't actually apply 1 to newly imported objects. Lame
    My first idea was to override the model importer inspectorGUI, and add a tick box, but DrawDefaultInspector doesn't, you know.... draw the default inspector
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    thank you greatly for trying, please let me know if you have any ideas <3
     
  4. skusku

    skusku

    Joined:
    Jan 4, 2015
    Posts:
    17
    a bit hacky:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System;
    4.  
    5. public class CustomImportSettings : AssetPostprocessor
    6. {
    7.     public float importScale = 1.0f;
    8.    
    9.     void OnPreprocessModel()
    10.     {
    11.         ModelImporter importer = assetImporter as ModelImporter;
    12.        
    13.         if(importer.globalScale < 1.0f)
    14.         {
    15.             importer.globalScale = importScale;
    16.         }
    17.     }
    18. }
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    Why?
    The only thing this does different is doesn't turn the scale down if it's higher than 1.0, that doesn't actually solve anything or make any difference to the issue