Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback ScriptedImporter: No way to detect Reimport event

Discussion in 'Experimental Scripting Previews' started by AnthonyReddan, Jul 11, 2020.

  1. AnthonyReddan

    AnthonyReddan

    Joined:
    Feb 27, 2018
    Posts:
    39
    Myself and my colleagues use ScriptedImporters alot nowadays as it allows us to do certain data processing up front instead of during the build process or worse, at runtime. One thing that has come up a number of times now though is that we have no way to get a hold of the currently imported asset prior to a Re-import.

    I've tried
    OnPreprocessAsset()
    in an
    AssetPostprocessor 
    but the old asset has already been destroyed. We have a number of use cases for this:
    1. If the data we've currently got imported is already in the right format according to the serialized import parameters, we want to prevent reimport (we've had this recently with certain custom texture compression importers, where we get a reimport just because we change the AssetBundle or another unimportant serialized field in the importer).
    2. I have an importer which creates a serialized object. That serialized object allocates a NativeArray for some of its serialized data for performance (in editor and runtime) in OnEnable and it disposes of it in OnDisable. We do not get an OnDisable call on our ScriptableObject on a reimport, so we leak memory in the editor.
    We'd like some way to get a hold of our previously imported object right before a reimport occurs so we can react accordingly.
     
    MostHated likes this.
  2. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Hey there, sorry for the necro, but searching for a way to detect and handle this is what lead me to this post. Did anything ever come of this, that you are aware of that let you accomplish what you are after?