I am moving into the art stage of my development pipeline, and it has become very tedious to go to every model and set it's import scale to 1.0 (the convention which my studio follows). This is becoming very tedious, and I would like to write a custom asset importer which will take assets when they are first imported and set their import settings to a new scale. This is to work around the problem that unity should already have options for default import settings! The problem with using the AssetPostProcessor class right now is that it applies to every single asset import, not the first import. This means that any change I make to the import settings with this class will be reflected on every single import. Do you have any solutions which might help me selectively apply the custom import settings? Unfortunately, when the asset importer reaches the PreProcess stage, the AssetImporter already exists, so checking for an asset at the assetPath can't yield whether the asset is importing for the first time or not. My other solution would be to maintain a list of assets which I have already PreProcessed, but this would create serious problems if that list were damaged somehow. My other thought is to somehow save on each asset whether it was preprocessed yet or not. However, I looked through the variables available on the asset importer and I can't find any that are unused in my game that I could use as a hook. Are there any methods of attaching additional information to an asset importer? Thanks for any help you can offer.
Well, I found a solution to the problem that works to my liking. Here is the script if anyone is interested: Code (csharp): public class AssetProcessing { [MenuItem("Assets/Processing/SetMeshDefaults")] public static void SetDefaultMeshSettings () { foreach(Object o in Selection.objects){ if(!AssetDatabase.Contains(o)) continue; string path = AssetDatabase.GetAssetPath(o); ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter; if(importer!=null){ importer.globalScale = 1.0f; importer.importMaterials = false; importer.generateAnimations = ModelImporterGenerateAnimations.None; AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); } } Selection.objects = new Object[0]; } }
Hello Same issue here, actually I have resolved it with: Code (csharp): public class FBXOverride : AssetPostprocessor { public void OnPreprocessModel() { ModelImporter importer = assetImporter as ModelImporter; String name = importer.assetPath.ToLower(); if (File.Exists(AssetDatabase.GetTextMetaFilePathFromAssetPath(name))) return; if (name.Substring(name.Length - 4, 4)==".fbx") { importer.globalScale = 1.0F; importer.animationType = ModelImporterAnimationType.None; importer.importAnimation = false; importer.materialName = ModelImporterMaterialName.BasedOnMaterialName; } } }
Hello @iwHiteRabbiT, This solution worked perfectly with Unity 2018 and previous, but not with Unity 2019. It seems that now the .meta files are created before OnPreprocessModel gets called. Do you have any solution to detect the first import with Unity 2019?
Ok, I found a solution: The function ModelImporter.importSettingsMissing returns true when a model is imported for the first time.
Note: importSettingsMissing only returns true if the asset has no sibling .meta file, which isn't necessarily the same as "the first time it was imported". For example, if you give somebody a .png and its associated .png.meta, then it importSettingsMissing will return false.