- Home /
Only PreProcess assets on first import.
hey folk,
i have the issue, that a beloved utility script of mine, which i used for years now, stops working as expected. i use an editor script which deactivates a lot of, for my project, unneeded components from models at first import. for example:
private void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
Object asset = AssetDatabase.LoadAssetAtPath (importer.assetPath, typeof(Object));
if (!asset)
{
importer.materialImportMode = ModelImporterMaterialImportMode.None;
importer.animationType = ModelImporterAnimationType.None;
importer.importAnimation = false;
Debug.Log("Model Import: override import settings for: " + importer.assetPath);
}
}
the pre processor gets always called if a model is imported or reimported, by changing its settings for example. now my issue is, that the old way of asking if the model is new, or already exists in the asset database, doesnt work anymore with the current unity version.
in older versions the asset variable in the example got only assigned, if the asset already exists, so the if statement was only executed at new imports. now, it is always assigned, so every time i change a setting, override a model, or switch platform, it have to execute the hole function, otherwise it would never be called.
ot i have tried a couple of different things, like asking, if there is already a meta file, but it seams that the new unity version creates this all before preprocession now.
here are some sources on how it works back in the days: https://answers.unity.com/questions/654816/only-postprocesspreprocess-on-new-assets.html
https://forum.unity.com/threads/first-asset-import.136393/
long story short, how can i differ between new and already existing models at import?
thank you for your time reading this and it would be great if you could help me out with this!
Answer by mikelortega · Oct 20, 2020 at 02:49 PM
You can detect the first import with AssetImporter.importSettingsMissing
Checking if (importer.importSettingsMissing)
will return true the fist time a model is imported, false once it's been imported and future reimports.
Your answer
Follow this Question
Related Questions
Imported model looks weird. 1 Answer
How can I get Unity to respect mcs.rsp changes between multiple builds? 0 Answers
Bug: Broken 2D PSB Models after upgrading Unity from 2019.3.7f1 to 2019.4 LTS 0 Answers
Adding primitive collider to armature from imported blender model issue 0 Answers
Why can't I change anisotropic level in a 2D sprite's import settings? 3 Answers