• Unity
  • Finished import callback

Harald we need to do our import processing things and it would help us a lot if we have import finished callback so that we hook right after it and do our things. Is there a way to get to know when spine has finished with the import procedures?

Related Discussions
...
2 years later

Harald
I have a problem with this approach when I transfer two or more animation folders into the project. OnPostprocessAllAssets catches only the last created _SkeletonData.asset. The rest of the created _SkeletonData.asset files do not trigger this callback.

Unity version 2022.3.22f1

Harald
Yes, the issue persists. It seems like these are unrelated cases.
We've opted out of Parallel Importing in our project in favor of working presets.

Regarding adding multiple animations simultaneously. SkeletonData is created from OnPostprocessAllAssets using the AssetDatabase.CreateAsset method. This method CreateAsset in the code has an attribute with a comment:
"[PreventExecutionInState(AssetDatabasePreventExecution.kImportingAsset, PreventExecutionSeverity.PreventExecution_Warning, "AssetDatabase.CreateAsset() was called as part of running an import. Please make sure this function is not called from ScriptedImporters or PostProcessors, as it is a source of non-determinism and will be disallowed in a forthcoming release.")]"

I believe this is exactly what prevents my code from executing when adding each animation. I attach a photo of my code.

    I think for now I will use a workaround with OnWillCreateAsset(string assetName). All created objects come there, without exceptions.

      @Sergey Hm, this is strange. According to this posting by a Unity developer from Nov 2023, OnPostprocessAllAssets should not pose any restrictions:

      "The documentation is correct. The naming of "OnPostprocessAllAssets" is misleading in that it is not a normal postprocessor (those are being run as part of an import of a specific asset). It is rather a callback done after all assets have been imported. Everything is allowed in this callback."

      Did you ever receive the warning you mentioned, "AssetDatabase.CreateAsset() was called as part of running an import."? Or did you just see it in code?

      Sergey I think for now I will use a workaround with OnWillCreateAsset(string assetName). All created objects come there, without exceptions.

      Thanks for the info, always much appreciated. It might perhaps be helpful with the other issue regarding parallel import and texture presets.

        Harald

        No, I have not received any warnings.
        I thought that it might not be displayed, as AssetDatabase.CreateAsset() is called through your handler.
        I did not continue investigating the problem. I implemented a workaround using a preprocessor.

          Sergey I thought that it might not be displayed, as AssetDatabase.CreateAsset() is called through your handler.

          I'm not sure I understand the logic of the above sentence. If OnPostprocessAllAssets would be problematic, it should issue the warning. If it's not problematic (it shouldn't be according to the Unity dev's posting), it should not issue any warnings.

          If OnPostprocessAllAssets is not allowed to call AssetDatabase.CreateAsset() (while "not allowed" includes leading to undefined behaviour), this is a bug on Unity's side.

          5 days later

          @Sergey Thanks very much for the additional info! I indeed must have misunderstood this part of the Unity discussion thread, that it also affects OnPostprocessAllAssets.

          It's a pity that effectively "Everything is allowed in this callback" seems to translate to "It doesn't explode, but some calls will no longer have the expected side-effects and you need to call experimental undocumented functions to write your assets to the artifacts directory, then hope it also gets imported and also written to the target Assets directory." This is not exactly great design and documentation on the Unity API front. 😃

          I have a problem with this approach when I transfer two or more animation folders into the project. OnPostprocessAllAssets catches only the last created _SkeletonData.asset. The rest of the created _SkeletonData.asset files do not trigger this callback.

          Unfortunately I could not reproduce this behaviour on 2023.2.16 with a separate class and the OnPostprocessAllAssets callback, I received a callback for each _SkeletonData.asset file with none missing.

          Since the workaround on the Unity forum here is neither clear (shall we write unique files to the Artifacts dir, and then what next?) nor clean, we will wait until Unity provides a proper solution, and until this becomes a real problem.

          Anyway, thanks again for sharing your findings!