• Unity
  • AddAnimation interrupts SetAnimation almost immediately

Related Discussions
...

Hi there,

I found some old posts on this, but they'd mentioned this was fixed. However it doesn't appear to be.

I am using SetAnimation to set a non-looping animation and then on the next line I use AddAnimation to queue a looping idle. However the idle seems to trigger almost immediately.

Am I using this incorrectly?

Thanks!

I just tried it on Spineboy. Works fine.

skeletonAnimation.AnimationState.SetAnimation(0, "run", false);
skeletonAnimation.AnimationState.AddAnimation(0, "idle", true, 0f);

Hmm very strange. Without the AddAnimation, my shoot plays all the way through. But with it it cuts off almost straight away. Could there be anything done incorrectly in the Spine file that might cause it to end prematurely?

Nothing quite comes to mind.

Have you tried reproducing your problem in the simplest case, using different skeletons and confirming that it is in fact your specific animations or skeletons that's causing the problem?

Make sure they're on the same track. Post your code if you're unsure.

16일 후

Hi there,

Sorry about the delay. This is the code I'm using:

void ChangeActiveEquipment(EquipmentDataBase newEquipmentData) {
    Timing.KillCoroutines(_changeActiveEquipmentCoroutine);

UpdateSkin(_activeEquipment, newEquipmentData);

float duration = 0;

if (_activeEquipment != null) {
    Animation animation = _spineAnimationState.Data.SkeletonData.FindAnimation(GetSwitchAnimationName(_activeEquipment, newEquipmentData));

    if (animation != null) {
        _spineAnimationState.SetAnimation(0, animation, false);

        duration = animation.duration;
    }
}

_spineAnimationState.AddAnimation(0, GetAnimationName(IDLE, newEquipmentData.EquipmentTypeAnimationName), true, 0);

_activeEquipment = newEquipmentData;

_changeActiveEquipmentCoroutine = NetworkManager.WaitForSeconds(duration, OnChangeActiveEquipmentComplete);
}

void UpdateSkin(params EquipmentDataBase[] equipmentData) {
    Color baseColor = _baseSlot.GetColor();

_loadoutSkin = _loadoutSkin ?? new Skin("Loadout");
_loadoutSkin.Clear();

foreach (EquipmentDataBase equipment in equipmentData) {
    if (equipment == null) { continue; }

    _loadoutSkin.Append(_spineSkeleton.Data.FindSkin(equipment.AnimationName));
}

_spineSkeleton.SetSkin(_loadoutSkin);

_spineSkeleton.SetSlotsToSetupPose();
_spineAnimationState.Apply(_spineSkeleton);

SetBaseColor(baseColor, 0);
}

static string GetSwitchAnimationName(EquipmentDataBase from, EquipmentDataBase to) {
    return string.Format(SWITCH, from.EquipmentTypeAnimationName, to.EquipmentTypeAnimationName);
}

Removing the _spineAnimationState.AddAnimation line results in the animation playing right through. But without it, it gets interrupted early.

You should create a simple test script to narrow down the causes. Slowly reintroduce the complexities until you produce the problem again.
Also check your SkeletonDataAsset for what default mix duration settings you set.

Pharan wrote

Also check your SkeletonDataAsset for what default mix duration settings you set.

This was it! It was set to 0.2s, setting it to 0 fixed the issue! Thanks!

It should've only been a problem if the animation in SetAnimation was also about 0.2 seconds in duration.
In these cases, you may want to change the delay or MixDuration of your resulting TrackEntry from AddAnimation.

Setting the default to 0 means you'll lose all your mixing. That's desirable for some setups, but may not be what you want. Depends on how you're animating though.

Pharan wrote

It should've only been a problem if the animation in SetAnimation was also about 0.2 seconds in duration.
In these cases, you may want to change the delay or MixDuration of your resulting TrackEntry from AddAnimation.

They are very short animations, and they're also swapping out sprites, so no mix is desirable. However I've just looked at the returned TrackEntry you suggested and will actually set it there. Thanks again!