- Home /
is it possible to have a global/static variable in the AssetPostprocessor script
I am trying to figure out if there is a constructor/start/awake kinda event on this object, but the documentation needs a little further development it seems at the moment.
I need to have somekinda static value or something that I can count, because when I do multiple imports, I get the event pr. model (which is great btw), but I need to calculate how many + assign certain values to the model, depending on how many I already have.
This one fires nicely:
void OnPreprocessModel ()
{
ModelImporter proc = (ModelImporter) assetImporter;
Debug.Log(proc.assetPath);
}
But is there any "before we start to import xx models" function that can initialize a counter etc.?
Edit #1 I would like to be able to have ZERO value before running the "Reimport" which can be fired with right mousebutton on any Ressource folder.
If its a static, it keeps going up and up and thats great while importing, but afterwards or before, I need to be able to set it back to zero for next run.
Reason is that I would like to build some kinda PROGRESS indicator for the import, like 234 of 3424 models.
Right now, my only option is to make a menu function that resets the static value or let the server return the "count". But the server ALSO needs to know when to start over.
Lastly, I cant seem to get WWWform to work with AssetsImporter ??? cant corutines be spawned from within this?
Possibly you are trying to achieve your ultimate goal (which is?) in a way that cannot work. The user can reimport assets whenever they want, individually or in bulk. If you need the number of a certain asset, then the only reliable way to do that would be to look for all of them whenever an asset is imported (or just when added or deleted if you only need the count). You could try to save this state and updating it incrementally, but you risk getting out of sync.
What is your ultimate goal?
okay, I'll try to explain it in the question. Just a sec! :o)
Answer by Paulius-Liekis · Aug 02, 2011 at 02:23 PM
Just define static variable (I don't know syntax for JavaScript) and then use it. If you want Init call for your static variables, you can always create "static bool initialized = false;", and then check for that in OnPreprocessModel and call your Init method if it hasn't been initialized.
Maybe you could just define a constructor for your AssetPostprocessor, although I can't remember how long Unity keeps the instance of each AssetPostprocessor.
C# syntax is fine by me. Regarding your static bool initialized, when will it be reset then? if I do a reimport, it should be initialized.
static variables live forever (read: as long as you have Unity running; they get reset if you recompile your scripts).
if you aren't satisfied with that lifetime, you can use PlayerPrefs :)
Static variables in C# do not "live forever." They last for as long as the object's lifetime. Once the object is marked for GC the static variable, like all other member variables within the class, become invalid.
Just tried to use the initialized in unity 3.4, first the editor crashed (which 3.4 does a lot I think) and then on reopening the project the first model import said initialized and the rest was already initialized. Problem is though, it does not go back to un-initialized even after the Reimport all function is run again. Problem still unsolved.
Constructor idea: Assets/Editor/FBXimporter.cs(35,14): error CS0542: `FBXimporter.FBXimporter()': member names cannot be the same as their enclosing type
Your answer
Follow this Question
Related Questions
Creating a prefab in AssetPostprocessor.OnPostprocessAllAssets(). 1 Answer
Modify sprite geometry using AssetPostprocessor 0 Answers
How do I programmatically assign a GameObject to a prefab? 6 Answers
AssetPostprocessor (in dll) doesn't work when there's a compiler error in another script 0 Answers