We’ve been experiencing an issue where a handful of our spatially loaded actors have sometimes unexpectedly been playing a looping animation. These actors have a SkeletalMeshComponent on them which is set with the default Animation Mode of AnimationBlueprint/‘Use Animation Blueprint’. At runtime we sometimes play specific animations on them with the ‘Play Animation’ function on the Skeletal Mesh. When this is called, the Animation Mode variable is changed by that function call at runtime to AnimationSingleNode/‘Use Animation Asset’.
We have identified that our issue occurs when the player walks away from these actors, causing them to unload and hit their EndPlay, and then the player walks back again before they are garbage collected, causing the same actor and components to be reused once again. What we’re seeing then in BeginPlay is that the Animation Mode has been left in this AnimationSingleNode/‘Use Animation Asset’ state - rather than the class default of AnimationBlueprint/‘Use Animation Blueprint’.
Normally this would not be a great issue as the user would not have been able to set the ‘Anim to Play’ variable in the blueprint without the animation mode having been set to ‘Use Animation Asset’. However, for these blueprints the ‘Anim to Play’ variable seemed to have an animation stored in it, and this was the animation we were seeing play out - this variable was invisible to the user when the Animation Mode was left at its default of ‘Use Animation Blueprint’, so there was no visibility that anything was set there. Presumably this component had previously used a different Animation Mode or the variable was accidentally set at one point. What we see here is with this modified Animation Mode on BeginPlay, this hidden but set ‘Anim to Play’ animation is then automatically started to play out in a loop (as the ‘Playing’ and ‘Looping’ options are enabled by default).
Given our stage in development, the safest fix for us is just to modify these actors Blueprint classes - temporarily changing the Animation Mode to ‘Use Animation Asset’ to expose the variable, clearing the ‘Anim to Play’ variable, and setting the Animation Mode back to the default ‘Use Animation Blueprint’. This doesn’t prevent the Animation Mode from persisting in its modified state, but it does stop the looping animation from kicking in when this occurs.
We do have an alternate fix that we were thinking of integrating into our code for future work - of resetting the Animation Mode variable back to the original value found on the ClassDefaultObject in USkeletalMeshComponent::EndPlay. We were wondering if this fix seems reasonable or if there might be some potential ramifications to it that we may be unaware of? It may also be useful to propose in case anyone else experiences the same issue. I have attached the code below:
void USkeletalMeshComponent::EndPlay(EEndPlayReason::Type Reason)
{
Super::EndPlay(Reason);
// If the Animation Mode has been changed at runtime, set it back to the default in case we reuse this component
if (GetOwner() && GetOwner()->GetClass())
{
const USkeletalMeshComponent* defaultComponent = AActor::GetActorClassDefaultComponentByName<USkeletalMeshComponent>(GetOwner()->GetClass(), GetFName());
if (defaultComponent && (defaultComponent->GetAnimationMode() != AnimationMode))
{
SetAnimationMode(defaultComponent->GetAnimationMode());
}
}
}
Thanks,
Tom
[Attachment Removed]