• Unity
  • Move to end of animation slight flicker

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

Hi there!

I'm currently trying to move to the end of an animation as soon as it starts. I found this post and have tried out the instructions in there, however I am seeing a very brief flicker of the animation in between:

Fast forward an animation to near the end?

Here's the code I'm using:

void MoveToEnd() {
    TrackEntry trackEntry = _spineAnimationState.SetAnimation(0, GetEquipmentStateAnimation(EquipmentState.Lowered, 
    EquipmentState.Raised), false);
    trackEntry.mixDuration = 0;
    trackEntry.TrackTime = trackEntry.Animation.Duration;

UpdateSkin(_activeEquipment);
}

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

_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);

SetColor(baseColor, 0);
}

Not sure what flicker you might be talking about though.

Sorry, I mean I'm seeing either the start of the animation, or some position during it very briefly before it snaps to the end position.

I suppose this depends on when you're calling MoveToEnd or on other code.

Note that AnimationState.Apply(Skeleton) poses the skeleton according to the current state of AnimationState. And then SkeletonAnimation's LateUpdate uses the skeleton's pose to update the Mesh.

If something in the code overrides your changes, or you make changes to AnimationState but the mesh has already been updated, the resulting visible thing in that frame may not be what you expect.

Is there a way to trigger the LateUpdate manually to ensure the mesh is correct? It doesn't seem to be accessible from SkeletonAnimation.

Just call skeletonAnimation.LateUpdate()
It's a public method.