• Unity
  • Correct way to set SkeletonDataAsset.atlasAssets ?

I'm writing a script that assigns SpineAtlasAsset objects to SkeletonDataAsset objects, using code like this:

var skelDataRef = AssetDatabase.LoadAssetAtPath<SkeletonDataAsset>(skelDataPath);
var atlasRef = AssetDatabase.LoadAssetAtPath<SpineAtlasAsset>(atlasPath);
skelDataRef.atlasAssets[0] = atlasRef;

Originally, this code would work, but only until Unity was relaunched, at which point the change would be seen to have not persisted.
So, I added this:

EditorUtility.SetDirty(skelDataRef);
AssetDatabase.SaveAssets();

And, strangely, this works


but only AFTER Unity has been relaunched! For some reason it now does not reflect my changes until I've totally quit the Editor (not even if I close and re-open the current scene).

Is there anything obvious that I'm missing here? I even tried changing

skelDataRef.atlasAssets[0] = atlasRef;

to

skelDataRef.atlasAssets = new SpineAtlasAsset[]{atlasRef};

in case there was a setter involved, but it doesn't seem to have changed anything... What's the proper way to give a Skeleton asset a new Atlas in code, in a permanent way?

Related Discussions
...
  • Изменено

Thanks for reporting, you seem to have found a bug there. I could reproduce that changing the Atlas Assets property at the SkeletonData asset Inspector does not automatically reload the skeleton data accordingly. Workarounds would be to either select the SkeletonData asset in the project panel and from the context menu select Reimport, or alternatively select an instance of the skeleton in a scene and in the Inspector hit the SkeletonData Asset Reload button which reloads the skeleton data.

The programmatic way would be to call SpineEditorUtilities.ReloadSkeletonDataAsset(skeletonDataAsset), which is what the Reload button does (apart from calling ReinitializeComponent(component) as well to reload the instance).

I have created an issue ticket here:
https://github.com/EsotericSoftware/spine-runtimes/issues/2037
I will let you know once the issue has been resolved.


This issue has just been fixed on the 4.0 branch. The commit will soon be merged to 4.1-beta as well.
A new spine-unity unitypackage is available for download here as usual:
Spine Unity Download: Download

Please note that the above fix shall fix reloading when changing the atlas asset via the Inspector, but your editor script might still need to call SpineEditorUtilities.ReloadSkeletonDataAsset(skeletonDataAsset) and ReinitializeComponent(component) as described above.

Thank you!! SpineEditorUtilities.ReloadSkeletonDataAsset(skeletonDataAsset) and ReinitializeComponent(component) has it all working like it should. 🙂

Glad to hear, thanks for letting us know! 🙂