• Unity
  • AnimationReferenceAsset improvements discussion

  • Modificato
Related Discussions
...

This thread has been created to continue the discussion started here on this forum thread under a more suitable topic name:
Unity Log for null animations
I've opened a properly named thread here so that everyone who is interested in this topic can participate.


foriero ha scritto

Harald, is there a reason why spine animations assets are not grouped into one master asset? We have thousands of animations and if I use what you suggest then our project have thousands of files added. :-( Moreover if you group them into master asset it can simply live next to skeleton data file. And if people need to do their own assets they will create custom master asset and add there SpineAnimationAsset and reference them from there.

What I propose have SpineAnimationAssetGroup and SpineAnimationAsset. Generate it automatically when importing. Since this way we have only one file it is not a problem to do so. Does it make sense?


Thanks for sharing your thoughts. I'm answering here instead of replying to your mails so that others can participate in the discussion as well.

foriero ha scritto

Didn't know about AnimationRefereceAsset.

Oh, ok, I assume the example scene Spine Examples/Getting Started/3 Controlling Animation Continued didn't exist when you started using spine-unity years ago, as it demonstrates it rather early in the list of example scenes.

foriero ha scritto

Much cleaner and only one file in repository instead of thousands of individual animation references files.
[..]
Harald, is there a reason why spine animations assets are not grouped into one master asset? We have thousands of animations and if I use what you suggest then our project have thousands of files added. :-( Moreover if you group them into master asset it can simply live next to skeleton data file. And if people need to do their own assets they will create custom master asset and add there SpineAnimationAsset and reference them from there.

The main reason is that these assets have already been generated this way in earlier spine-unity versions, and changing the structure always comes with additional effort to ensure automatic updates without breaking existing projects. Unfortunately there are currently too many far more important tickets remaining, whereas users would not benefit much from this feature (subassets at a single asset file vs. assets in a subfolder).

foriero ha scritto

What I propose have SpineAnimationAssetGroup and SpineAnimationAsset. Generate it automatically when importing. Since this way we have only one file it is not a problem to do so. Does it make sense?

foriero via email ha scritto

If this bank can be created and updated automatically I think it will help a lot the animation workflow in Unity.

It seems as if you have reimplemented part of the functionality already provided by SkeletonData.
When I suggested using the SetAnimation() overload variant taking the Animation object parameter I mainy meant that you should be caching and re-using an Animation object, which SkeletonData.FindAnimation(animationName) returns instead of implicitly calling FindAnimation() every time.

So I would suggest using the name strings to setup your assets, but in your code you should resolve them to a cached Animation object once at e.g. Start(). I currently don't really see any benefit in a SpineAnimationAssetGroup class with additional methods, but if you have some other use case in mind, please let us know.


@foriero Answering the email here again so that others benefit from the discussion.

Having seen your email about your project structure and your problems with it, I would summarize your issues as follows (if anything is wrong, please lmk):
1) You have many/all skeletons placed in a flat directory instead of in subdirectories per skeleton.
2) When selecting Create Animation Reference Assets all generated AnimationReferenceAssets are placed in the directory ReferenceAssets which is now shared by multiple skeletons, they all dump their reference assets in this directory.
3) You prefer having a single asset file with many nested AnimationReferenceAssets as sub-assets, instead of many separate AnimationReferenceAsset files.
4) When you have an AnimationReferenceAsset property in the Inspector and are clicking the asset selector next to the property, it lists all AnimationReferenceAssets in the project, instead of only listing assets suitable for a specific skeleton.


Now about answers to those issues:

1) You have many/all skeletons placed in a flat directory instead of in subdirectories per skeleton.

Why are you placing all your skeletons in a single directory and don't create a subdirectory for each one? This would automatically solve the problem of having all AnimationReferenceAssets put into a single common directory.

2) When selecting Create Animation Reference Assets all generated AnimationReferenceAssets are placed in the directory ReferenceAssets which is now shared by multiple skeletons, they all dump their reference assets in this directory.

Admittedly this is not good at all, the directory should either a) be named containing the skeleton name to have a unique sub folder, or at least allow and track renaming after creation of the folder (currently it generates a new directory ReferenceAssets when selecting Create Animation Reference Assets and they already exist in a renamed folder).

3) You prefer having a single asset file with many nested AnimationReferenceAssets as sub-assets, instead of many separate AnimationReferenceAsset files.

This is admittedly perhaps cleaner in your git/svn commit log. I would also favour such a structure, but automatic transition needs to be implemented and tested properly.

As you've sent some code via email, I would need to check this, but currently I'm afraid we don't have time yet for this rather low-priority feature.

4) When you have an AnimationReferenceAsset property in the Inspector and are clicking the asset selector next to the property, it lists all AnimationReferenceAssets in the project, instead of only listing assets suitable for a specific skeleton.

This is indeed not optimal. While Unity's animation clips selection is behaving similarly bad, that should not be an excuse to have a bad solution, too.

Drag-and-drop of the AnimationReferenceAsset from the folder where all AnimationReferenceAssets of a single skeleton are (see [1]) should currently be the workflow which automatically "limits" the number of animation reference assets to choose from. Nevertheless, a clean and easy solution for clicking the asset selector and getting listed only suitable reference assets would be nice.

I have opened this issue ticket here:
https://github.com/EsotericSoftware/spine-runtimes/issues/1940

It would be nice if there is some discussion about whether other users also face such issues, and how they might already be tackled efficiently. So everyone: Please share your thoughts and opinions here if you've encountered problems (or created workarounds / solutions) in regards to using AnimationReferenceAssets, or how you deal with them efficiently and avoid any issues in the first place. Thanks in advance! :nerd:

19 giorni dopo

Hey Harald, I just noticed this thread, probably would be worth pinning.

Since I made a post regarding an issue with AnimationReferenceAsset, I'll chime in.

I have a problem with the Initialize function, it's quite an edge case, but if I have a timeline track that references a legacy skeleton that's an old 3.8 skeleton after upgrading to 4.0, GetSkeletonData will return null, resulting in a NullReferenceException in this line:

this.animation = skeletonDataAsset.GetSkeletonData(AnimationReferenceAsset.QuietSkeletonData).FindAnimation(animationName);

The consequence is that it's no longer possible to even open and edit the timeline to fix it, as the error just prevents the timeline from loading.

Adding a null check after GetSkeletonData fixed it for me:

this.animation = skeletonDataAsset.GetSkeletonData(AnimationReferenceAsset.QuietSkeletonData)?.FindAnimation(animationName);

I'll add a comment in the github issue.


On to some other remarks regarding ReferenceAsset workflow, all mostly related to unity Timeline, which is my main way of working with ReferenceAssets

1) Renaming animations:
One of the big problems I have is that if for any reason my animator renames an animation in their spine project, this will generate a new ReferenceAsset, which will cause my timelines to break. So I have to tell my animators to never ever change animation names.

I think one way to fix this would be to have some sort of GUID generated in the json when an animation is created, and if an animation is ever renamed, the GUID stays the same.

Now in Unity, there's obviously going to be some work to be done when doing the import, because if you just generate a new ReferenceAsset, it will have its own asset ID within Unity, and the references would still be pointing to the old, obsolete, ReferenceAsset. I suppose one way to do this would be to check for each animation if there's already a ReferenceAsset with the same GUID, and if there is, it would rename the old file and update it (probably with a warning message).

Doing this should, I think, allow unity to keep referencing the proper newly named ReferenceAsset.

2) Selecting an animation clip in unity Timeline
If I need to reference an animation for a specific skeleton in a monobehaviour, I can use the [SkeletonAnimation] attribute and get a nice dropdown list of animations. Super simple.
However it's not as simple in unity Timeline. If I want to directly change the animation from the clip, I get a list of all referenceassets in my project.

The easiest way right now is to browse my project view and drag + drop the proper reference. That's ok but it takes me some extra time to do so. If instead of this:

I could get this:

I believe it would significantly improve my workflow.

I do realise though this may not be a simple thing, as timelines have a different scope than monobehaviours.

Another solution to speed up my workflow would be to rename all my animations so that their names are structured as <skeletonName><animationGroup><animationName>, which is something I've started asking of my animators. This would at least speed up the search in my project, but I can't rename existing animations (see point 1)

3) visualizing animation events in the timeline:
this one is to be put in the "could be nice, definitely not a priority" category. I'm making extensive use of animation events for all kinds of stuff, but sometimes I want to synchronize stuff that is happening in my timeline with an event that is raised in the animation. Right now the way I do it is to roughly estimate, from the animation preview, where that event happens. It's generally not too much of a problem if there's a clear visual cue from the animation itself. But sometimes the approximation is not great and I have to double check with my animator to ask him when exactly I should do it. If there was some visual indication within the clip (a vertical purple line or something like that) that there's an event (doesn't need to tell me the name of the event) that would be cool.
Another option would be to have a right-click to generate signals wherever there's an event on the clip.

Thanks very much for sharing your thoughts, @gofiguregames!

gofiguregames ha scritto

1) Renaming animations:
One of the big problems I have is that if for any reason my animator renames an animation in their spine project, this will generate a new ReferenceAsset, which will cause my timelines to break. So I have to tell my animators to never ever change animation names.

I think one way to fix this would be to have some sort of GUID generated in the json when an animation is created, and if an animation is ever renamed, the GUID stays the same.

This is a valid point, thanks for pointing that out.

gofiguregames ha scritto

2) Selecting an animation clip in unity Timeline

If I need to reference an animation for a specific skeleton in a monobehaviour, I can use the [SkeletonAnimation] attribute and get a nice dropdown list of animations. Super simple.
However it's not as simple in unity Timeline. If I want to directly change the animation from the clip, I get a list of all referenceassets in my project.

I think we might be able to resolve this problem by providing a custom property drawer for AnimationReferenceAsset.

gofiguregames ha scritto

3) visualizing animation events in the timeline:

We haven't thought of this yet, thanks for mentioning!