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?
Finished import callback
- Edited
Basically you could simply write your own AssetPostprocessor
class with OnPostprocessAllAssets
and handle any asset where the name ends with _SkeletonData.asset
.
Alternatively we have SkeletonDataModifierAsset
to be added at a SkeletonDataAsset
which I think you're already familiar with:
spine-unity Runtime Documentation: SkeletonData Modifier Assets
@Sergey Thanks for reporting. Does this also occur when you disable Parallel Import
in Unity's Project Settings?
It might be related to the issue reported on your other thread:
https://esotericsoftware.com/forum/d/25894-the-apply-atlas-texture-settings-is-not-working
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 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.
This is what I was talking about:
https://forum.unity.com/threads/cal...-during-asset-importing.1517806/#post-9488617
As I understand it, yes, this is a problem with Unity. And it is likely to affect the capture of multiple additions of SkeletonData.
I have already solved the problem bypassing it. And I found the information incidentally. But I will be happy if this helps you improve the product.
@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!