Hi, there’s no native or blueprint API to do this since we don’t track the number of times that an animation has looped in the Sequence players. But you could do this by storing some state data and then using an anim node function to increment it and another one to reset the data when entering/returning to the state.
I mocked something up quickly that I think should give you what you need. The code for the anim node function would look like this. I’m using a custom struct to store the state data, but you could just hold the variables directly on a custom anim instance, or just on your anim bp if you prefer:
`// .h
USTRUCT(BlueprintType)
struct FTransitionTrackerData
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Transition”)
uint8 TriggerAfterNumLoops = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Transition”)
bool bShouldTransition = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Transition”)
uint8 LoopCount = 0;
};
UFUNCTION(BlueprintCallable, Category = “Animation|Sequences”, meta = (BlueprintThreadSafe))
static ANIMGRAPHRUNTIME_API void TriggerTransitionOnLooped(const FSequencePlayerReference& SequencePlayer, UPARAM(Ref) FTransitionTrackerData& StateData);
// .cpp
void USequencePlayerLibrary::TriggerTransitionOnLooped(const FSequencePlayerReference& SequencePlayer, FTransitionTrackerData& StateData)
{
SequencePlayer.CallAnimNodeFunction<FAnimNode_SequencePlayer>(
TEXT(“HasSequenceLooped”),
[&StateData](const FAnimNode_SequencePlayer& InSequencePlayer)
{
if (InSequencePlayer.GetDeltaTimeRecord()->GetPrevious() > InSequencePlayer.GetAccumulatedTime())
{
++StateData.LoopCount >= StateData.TriggerAfterNumLoops ? StateData.bShouldTransition = true : StateData.bShouldTransition = false;
}
});
}`The idea is that in the struct, you can specify how many times you want the counter to loop. Then the anim node function will set bShouldTransition to true once you hit that number of loops. You can then use that to trigger the transition.
Your anim blueprint setup would then look something like this. First the Sequence Player:
[Image Removed]The OnUpdate function would call your library method:
[Image Removed]And the OnBecomeRelevant function resets the state data:
[Image Removed]Then you can base the transition to your other state based on bShouldTransition in the state data:
[Image Removed]You should then get a behaviour that looks something like the following. In this case, I’ve set the state data to allow the walk animation to loop two times, then we transition to run. The transition from run to walk just uses the automatic transition rule to trigger when the run animation finishes. We then transition back to walk and the OnBecomeRelevant resets the state data so we repeat the process.
[Image Removed]Let me know if you want to discuss this in more detail.