Hale_88

Hi all,

I've looked through the forums for the solution and so far have not found it.

Problem:
When we export from spine and import to Unity the SkeletonAnimator does not get the new animations and old animations are not updated. Which currently means that everytime we make a change we have to remake the SkeletonAnimator and then remake our Mecanim tree.

SkeletonData


Please note there are three Air Attacks and a Air Heavy attack before Air Slam. We then look at the SkeletonAnimator that is connected at the bottom of the Skeleton Data.

SkeletonAnimator


There is no Air attacks before Air Slam. This also holds true for any events that are put in an animation after the SkeletonAnimator was created.

Process
We export from Spine a new Json, Atlas and PNG for the Hero, adding .txt to the end of the Atlas. We then drop it into our project via the file explorer and replace all 3. We then open up Unity and can see the new animations in our SkeletonData but not our SkeletonAnimator.

What We've Attempted

Ensured that JSON, Atlas and SkeletonAnimator are all pointing the the right thing (This was done by double clicking on said items in the skeletondata in the inspector.)

Ensured that JSON does not have a .txt extension as that is said to have caused issues.

Read through these two forum posts and tried assorted things in each one

Add new animations to Mecanim Controller
url=http://esotericsoftware.com/forum/Adding-new-animations-to-Mecanim-Controller-4199?&hilit=mecanim+skeletondata&start=25

Mecanim animator not updating clips
http://esotericsoftware.com/forum/Mecanim-animator-not-updating-clips-5623?p=25758&hilit=mecanim+skeletondata#p25758

What we are using
We are using the following:
Spine2D: Version 3.1.02
Spine Unity Package: Downloaded March 9th, 2016
Unity: Version 5.3.1f1

Please help, I really really don't want to have to create our mecanim web thing words fail now
Hale_88
  • Сообщения: 23

Pharan

I just tried this now. It seems to work correctly without any extra steps. Did it several times, renaming, deleting or adding animations and re-exporting several times.

Have you tried selecting your SkeletonData asset, removing the Controller reference, then clicking Generate Mecanim Controller again?
That should prompt you to either Update or Overwrite. (I think want to choose Update so it doesn't nuke your existing mecanim animation state machine).

I didn't have to do that, but there might be more to your setup.
Аватара пользователя
Pharan
  • Сообщения: 5366

Hale_88

Pharan писал(а):I just tried this now. It seems to work correctly without any extra steps. Did it several times, renaming, deleting or adding animations and re-exporting several times.

Have you tried selecting your SkeletonData asset, removing the Controller reference, then clicking Generate Mecanim Controller again?
That should prompt you to either Update or Overwrite. (I think want to choose Update so it doesn't nuke your existing mecanim animation state machine).

I didn't have to do that, but there might be more to your setup.
Hi Pharan,

I hadn't tried that. So I did and then it didn't update but also gave me an error. I recorded what I did so you can see what steps I took.



In case you can't read it the error is as follows:
ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,UnityEngine.AnimationClip].Add (System.String key, UnityEngine.AnimationClip value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
SkeletonBaker.GenerateMecanimAnimationClips (.SkeletonDataAsset skeletonDataAsset) (at Assets/Plugins/Spine/spine-unity/Editor/SkeletonBaker.cs:405)
SkeletonDataAssetInspector.DrawUnityTools () (at Assets/Plugins/Spine/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs:149)
SkeletonDataAssetInspector.OnInspectorGUI () (at Assets/Plugins/Spine/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs:125)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1231)
UnityEditor.DockArea:OnGUI()
Hale_88
  • Сообщения: 23

Pharan

Ok. That error log really helps.
Error logged was here: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs#L405

To fix it:
Search for SkeletonBaker.cs in your project. Open it.
Look for that line (line 405) where it says:
clipTable.Add(o.name, (AnimationClip)o);
Could you replace that with this:
clipTable[o.name] = (AnimationClip)o;
Then try again.

This problem should theoretically not be happening unless... there were two animations that have the same name?
Аватара пользователя
Pharan
  • Сообщения: 5366

Hale_88

You Sir, are a gentleman and scholar.

You should get a promotion from Doorknob cleaner to full Door cleaner :p

Also we don't have animations of the same name, I'm pretty sure spine won't let you do that anyways.
Hale_88
  • Сообщения: 23

Pharan

Whoa whoa. Wait. There must have been some kind of weird thing going on 'cause that shouldn't have been happening. I'd hate for it to poke its head again later secretly.

Could you go back to that line and replace the whole foreach block with this?
foreach (var o in objs) {
if (o is AnimationClip) {
Debug.Log("adding " + o.name);
clipTable.Add(o.name, (AnimationClip)o);
}
}
So we can tell why it was adding duplicates, and where that was coming from. It could have been harmless, but it could also be something that would wreck your controller.
Аватара пользователя
Pharan
  • Сообщения: 5366

Hale_88

Yeah it would be really bad to get further in the project and have it happen again.

I put in the code, here are the results, really weird is that a couple of them are output twice.


At first glance it looked somewhat random but the ones that are output twice are ones that exist in my mecanim tree. With the notable exception of Upper_cut. These animations were also the first ones that were created
Hale_88
  • Сообщения: 23

Pharan

Ah, that's interesting. I guess stuff in the Mecanim controller's state machine actually counts as its own asset, but it's hidden in project view.
In that case, it should be safe as far as I can tell since we're specifically type-checking for (AnimationClip). Pretty sure they're pointing to the same asset object.

We'll continue keep an eye on this.
Аватара пользователя
Pharan
  • Сообщения: 5366

Hale_88

K, I will let you know it happens again as well.

Thanks for your help
Hale_88
  • Сообщения: 23

Pharan

Hey. So I looked into it more closely, found the Unity bug that was causing it, and have a more robust solution.
You can copy the entire code from this link: https://raw.githubusercontent.com/EsotericSoftware/spine-runtimes/master/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs
And paste that as the replacement code for your project's SkeletonBaker.cs

Posted a description of the bug here: http://forum.unity3d.com/threads/bug-hidden-duplicate-animationclips.391202/

Note that this newer code will also throw errors when other weird things are going on, so we can find them and fix them.
Аватара пользователя
Pharan
  • Сообщения: 5366

ZimM

Huh. I've tried to follow the steps described in your Unity forum post, but failed to reproduce it. Duplicated AnimatorState still points to the original AnimationClip. Unity 5.3.2f1.

As for OP issue, I've fixed it by modifying the block like this:
foreach (var o in objs) {
if (o is AnimationClip) {
if (!clipTable.ContainsKey(o.name)) {
clipTable.Add(o.name, (AnimationClip) o);
}
}
}
Serves me well for months.
Аватара пользователя
ZimM
  • Сообщения: 25

Pharan

I did a lot of Debug.Log stuff. I noticed that the duplicates come first (because it's iterated by the foreach first with the hidden state machine state objects) and the original AnimationClip comes later.

Doing it the the !(ContainsKey) way prioritizes the first thing you find.
The [key] = value way prioritizes the last thing you find.

Anyway, the point is, if the code was throwing exceptions because it was detecting duplicates, something weird is going on in Unity. If hidden duplicates weren't generated through duplicating animator states, they're certainly generated some other way.

So I've replaced the [key] = value code (which would have doing the right thing, just based on what I logged) with a HideFlags check to ensure that any other errors that happen will still surface and we can handle them appropriately when they do.
Аватара пользователя
Pharan
  • Сообщения: 5366

Hale_88

@Pharan So I updated to the SkeletonBaker.cs script, On Friday night we got new animations so this morning I updated the script and then put in the new Json, atlas and png.

The SkeletonAnimator did not update automatically. I removed the controller from the SkeletonData and clicked on Generate Mecanim and then clicked on update. It then updated all the animations. (So same thing as last time).

This is a workable work flow just not sure if SkeletonAnimator is suppose to be updated automagically or not.
Hale_88
  • Сообщения: 23

Pharan

No errors logged?
The whole time I was testing, it was doing things automatically without messing with the controller field.
So, it should do that. If it's not, something weird is going on. In that case, it' should have logged something.
It's a relief that the workaround is working though.

Since it's workable on your end, I don't want to bother you with reproing it or whatever, but if you have permission, you can send your json, atlas (and blacked out png) to unity@esotericsoftware.com so we can try to find out if there's some other weird case not caught in it.

Did you notice the bug I mentioned though? I mean I just hope you're aware of it (if it's happening with you) so it doesn't cause problems with incorrect durations or missing events as you're working with the state machine.
Аватара пользователя
Pharan
  • Сообщения: 5366


Вернуться в Unity