• Runtimes
  • Unity bug? (object disappears when switching animation)

Hi everyone,
I'm seeing an odd issue with the 2D Toolkit on Unity. I have two animations (idle and death), and when I call SetAnimation to switch to the death animation the object just disappears from the game.
Has anyone experienced similar issues? It's worth mentioning that switching the animation in the inspector window takes effect only after I check or uncheck "calculate normals".
My code is simple and almost entirely copied from the spineboy example.

public class Hittable : MonoBehaviour {
	private SkeletonAnimation skeleton;

// Use this for initialization
void Start () {
	skeleton = GetComponent<SkeletonAnimation>();
	skeleton.state.Event += Event;
}

public void Event (object sender, Spine.EventTriggeredArgs e) {
	Debug.Log(e.TrackIndex + " " + skeleton.state.GetCurrent(e.TrackIndex) + ": event " + e.Event + ", " + e.Event.Int);
}

// Update is called once per frame
void Update () {

}

void OnCollisionEnter2D(Collision2D collision) {
	skeleton.state.SetAnimation(0, "death", true);
}
}

Thanks!

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

If your colliding GameObjects had RigidBody2Ds, it's possible that your character just got pushed out of view by the collision reaction.

No?

And nothing on the console?

It's not a collision issue since the body is kinematic and not switching the animation doesn't create the same behavior. I'm also seeing that it does work with the spineboy example for 2d toolkit so it has to be something to do with my setup.
Anyone has any idea what could cause a skeleton to stop showing any sprites? Is it something to do with the 2d toolkit sprite collection/material perhaps?

Researching a bit more, it has something to do with the fact that my death animation replaces all sprites in the idle animation with just one sprite which is invisible in the idle state. If I make that sprite visible in the idle state as well it works fine (though that's not a viable solution as it does need to be hidden in the idle state).
So the problem is basically a sprite is only visible in an animation as long as it was present and visible in the original animation the object was created with.
Not sure if this is a spine bug or a 2d toolkit bug...

Sounds like a Spine bug. I'm currently going through editor issues and features, then I'll come back to this and other runtime issues. Sorry for the wait!

Great, thanks!

Strange. I do something similar sometimes and it works fine for me. But I have an autoreset callback (a SetToSetupPose call) for all my character spine animations.

Are you sure that image & slot's parent bone's scale is set to 1 in the death animation? Or could something else be affecting that slot's visiblity because it was changed by any of the previous animations and wasn't reset to normal by the death animation?

It's definitely not a scale issue and has something to do with the image not being visible in the original animation - if I set it to visible in the first animation and then switch to the death one I see it fine.
There's also no reset logic around it, it's a simple setAnimation call.

It's precisely the lack of reset logic that leads me to suspect that something from the previous animation is causing it not to be shown in the death animation.

It could also be a bug though, for all I know.

I'll take another look at this, perhaps you're right and SetToSetupPose will help.

6 дней спустя

Calling SetToSetupPose on the skeleton before changing the animation worked - though I'm still not sure what that does exactly 🙂

By default, Spine doesn't reset the positions, rotations, scales, keyed images or colors before playing a new animation. So if your current animation doesn't animate certain bones or images, they will stay as they were before the last animation ended.

SetToSetupPose resets the skeleton back to its Setup Pose, as it looks in Spine editor.

Likely, one of your previous animations somehow moved and animated a bone or slot in such a way that it made the death sprite invisible. Maybe it moved or rotated out of sight. Or the opacity changed.

10 дней спустя

hello!
i have an error with runtime Unity, C#
when i import folders spine-csharp, spine-unity to unity, in console i find a lot of bugs and skeleton (person) dont show on screen

Removing Assets/spine-unity/Assets/Spine/spine-csharp because the asset does not exist

Script 'Animation' has the same name as built-in Unity component.
AddComponent and GetComponent will not work with this script.

Assets/spine-unity/Assets/Spine/Editor/AtlasAssetInspector.cs(51,34): warning CS0618: UnityEditor.EditorGUIUtility.LookLikeInspector()' is obsolete:LookLikeControls and LookLikeInspector modes are deprecated.'

and more errors

my version of unity 4.3.1 f1
thanks

  • Изменено

@voanerges. This is a different topic.
But here's a reply anyway.

voanerges написал

Removing Assets/spine-unity/Assets/Spine/spine-csharp because the asset does not exist

This is harmless. Just a .meta file that got left over from the repo that Unity deleted.

@Nate: We should probably remove the meta file from the repo though. The spine-csharp folder's path doesn't affect Spine-Unity because it's just a bunch of classes and no Unity Components that need to be manually hooked onto GameObjects (MonoBehaviour attachments tend to break when when you move scripts around.).

voanerges написал

Script 'Animation' has the same name as built-in Unity component.
AddComponent and GetComponent will not work with this script.

This is also harmless. Spine.Animation is not a MonoBehaviour or a component so this really doesn't apply. It's a pretty dumb error, actually. But it happens once when you add Spine to the project then doesn't reappear ever again.

voanerges написал

Assets/spine-unity/Assets/Spine/Editor/AtlasAssetInspector.cs(51,34): warning CS0618: UnityEditor.EditorGUIUtility.LookLikeInspector()' is obsolete:LookLikeControls and LookLikeInspector modes are deprecated.'

This is kinda harmless. It won't affect the Spine user at all except for the annoying caution message that pops out. Unlike the first two, this message won't disappear. It's annoying, IMO.
@Nate: LookLikeInspector has been marked Obsolete. I'm not awfully familiar with editor scripts so I'm not sure what's supposed be changed. But I think in 4.3, you just have to remove the line. I vaguely recall reading the release notes and it said something about this, and about there being only one uniform look in the inspector stuff now (removing the need for LookLikeInspector). In any case, I don't know what that means for backwards compatibility of all editor scripts that used LookLikeInspector.. and do ask for a second opinion. XD

Any other errors?

thanks - after - a lot of time testing - i make it ! my little animation just show in unity - oh - a very nice examples you put on spine-unity!
but unity console - show some mistakes

Removed meta file and LookLikeInspector.