assetpostprocessor after editor has started a scene

Hi Guys,

Here is my issue,

I have a scene with a few placeholder object that need to be populated with strings as soon as a new model is loaded.

I have a new model that I’ve just added to the unity assets directory.
However, unity hasn’t started up yet.

I have a class called:
public class AutoLoad : AssetPostprocessor

Which does a bunch of stuff with adding names and variables to my level objects when a new model is loaded into unity.

The problem takes place when I run unity with this new asset, immediately on startup, unity will process this script with the model, but it hasn’t yet loaded the scene in the editor. So I get a bunch of errors because It can’t find the gameObjects in question to apply settings to.
Now, if I manually select the import button again, great it works, because by that time, the scene has loaded.

How do I suppress the updating/loading of new assets until my scene has loaded in the editor.

  • NOTE: At this point, I’m still not starting the game, I’m just perparing variables and populating gameobjects. Everything is done in the editor.

Any Ideas??

The only weird workaround i thought of, was to turn off autorefresh, and only turn it back on once my scene is loaded on startup. But even that isn’t trivial, because using this function: EditorPrefs.GetBool(“kAutoRefresh_h2404942332”) Will indeed tell me what the auto refresh status is in the prefs, but setting it to true doesn’t actually make any difference to my scene behaviour. It still believes it’s off if I manually set it.

Bump Does anyone have any ideas on this? I’m straining for some understanding. why is it when i set the key to be a value, it adds a new key with a simmilar name in the registry editor but doesn’t alter the existing one.

BUMP

If the information you’re looking to be capture exists in the scope of the scene, then this post processing should be handled in that same scope. That is to say, perhaps you should look at handling this in a scene post processor instead of at an asset level. Take a look at the PostProcessScene attribute for some more information. I would, during this callback, inspect the asset hierarchy of the project for the models that I am interested in and perform my per asset processing at this point.

An alternative would be that the information you’re looking to process exist outside the scope of any individual scene, at the level of the project. For this you could setup a ScriptableObject to store the data you’re interested in with your in scene behaviours referencing this. The added benefit here is that the data object would exist at the scope of the project and would therefore be accessible independently of any one specific scene being loaded.