x


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

more ▼

asked Nov 13 '11 at 05:19 PM

ronronmx gravatar image

ronronmx
806 84 101 122

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 18 '12 at 09:31 AM

nschrag gravatar image

nschrag
245 5 9 13

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!

Mar 19 '12 at 11:29 PM ronronmx

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.

Mar 20 '12 at 07:43 PM nschrag
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5099
x973
x420
x51

asked: Nov 13 '11 at 05:19 PM

Seen: 949 times

Last Updated: Mar 20 '12 at 07:43 PM