- Home /
OnPreprocessModel() override for individual changes???
So I can't figure out a way around this, and even though it has been talked about already, I never found a fix to this problem.
I am using the following code to process my fbx files on import:
using UnityEditor;
using UnityEngine;
public class FBXImportSettings : AssetPostprocessor {
void OnPreprocessModel () {
ModelImporter modelImporter = assetImporter as ModelImporter;
modelImporter.globalScale = 1;
modelImporter.addCollider = true;
modelImporter.generateAnimations = ModelImporterGenerateAnimations.None;
modelImporter.normalImportMode = ModelImporterTangentSpaceMode.Import;
Debug.Log("Importing model at: " + assetPath);
}
}
Works like a charm except it won't let me manually change settings...every time I change an import setting manually in the FBXImporter options, it reverts it back to the above values when I press 'Apply'.
Is there a way to prevent this from happening?
Thanks for your time and help,
Stephane
Answer by nschrag · Mar 18, 2012 at 09:31 AM
I'm not sure if there's an official way to do this, but here's a solution that definitely works.
Add a label to any asset where you want to override your AssetPostProcessor's defaults. To add a label, look at the bottom of the inspector for an ellipsis in a little blue button. Click it to add a label, something like "importoverride". Then, do the following in the asset processor script.
void OnPreprocessModel() {
List<string> labels = new List<string>(AssetDatabase.GetLabels(assetImporter));
if(!labels.Contains("importoverride")) {
// Do default processing behavior
}
}
If more advanced behavior were needed, you could add any number of labels to control the import process per asset.
Never thought of doing it this way...I completely forgot about labels, and I didn't even know you could access them via code, so thanks a lot for your answer, very helpful! Quick question: How do you "remove" a label? I messed up the name of a label I was adding and want to remove it now :)
Thanks again!
Removing labels is not terribly intuitive. When you click the ellipsis button, the labels on the current asset should appear highlighted in blue. Click on them there to remove them.
Your answer
Follow this Question
Related Questions
Create/Edit an AnimatorController using a script 0 Answers
How to look for a material in Assets folder and sub-folders? 1 Answer
How to auto rotate object on FBX import? 1 Answer
Is there a way to stop Unity importing an asset? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers