UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnimNode_RandomPlayer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "AlphaBlend.h"
8#include "CoreMinimal.h"
9#include "Math/RandomStream.h"
11
12#include "AnimNode_RandomPlayer.generated.h"
13
15{
16 Current,
17 Next,
18};
19
23USTRUCT(BlueprintInternalUseOnly)
25{
27
29 : Sequence(nullptr)
30 , ChanceToPlay(1.0f)
31 , MinLoopCount(0)
32 , MaxLoopCount(0)
33 , MinPlayRate(1.0f)
34 , MaxPlayRate(1.0f)
35 {
36 }
37
39 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings", meta = (DisallowedClasses = "/Script/Engine.AnimMontage"))
41
43 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings", meta = (UIMin = "0", ClampMin = "0"))
44 float ChanceToPlay;
45
47 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings", meta = (UIMin = "0", ClampMin = "0"))
48 int32 MinLoopCount;
49
51 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings", meta = (UIMin = "0", ClampMin = "0"))
52 int32 MaxLoopCount;
53
55 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings", meta = (UIMin = "0", ClampMin = "0"))
56 float MinPlayRate;
57
59 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings", meta = (UIMin = "0", ClampMin = "0"))
60 float MaxPlayRate;
61
63 UPROPERTY(EditAnywhere, Category = "Settings")
64 FAlphaBlend BlendIn;
65};
66
68{
69 // Index into the real sequence entry list, not the valid entry list.
71
72 // The time at which the animation started playing. Used to initialize
73 // the play for this animation and detect when a loop has occurred.
74 float PlayStartTime = 0.0f;
75
76 // The time at which the animation is currently playing.
77 float CurrentPlayTime = 0.0f;
78
79 // Delta time record for this play through
81
82 // Calculated play rate
83 float PlayRate = 0.0f;
84
85 // Current blend weight
86 float BlendWeight = 0.0f;
87
88 // Calculated loops remaining
89 int32 RemainingLoops = 0;
90
91 // Marker tick record for this play through
93};
94
95USTRUCT(BlueprintInternalUseOnly)
97{
99
101
102public:
104 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings")
106
107 // FAnimNode_Base interface
110 ANIMGRAPHRUNTIME_API virtual void Evaluate_AnyThread(FPoseContext& Output) override;
111 ANIMGRAPHRUNTIME_API virtual void GatherDebugData(FNodeDebugData& DebugData) override;
112 // End of FAnimNode_Base interface
113
114 // FAnimNode_RelevantAssetPlayerBase
116 ANIMGRAPHRUNTIME_API virtual float GetAccumulatedTime() const override;
117 ANIMGRAPHRUNTIME_API virtual bool GetIgnoreForRelevancyTest() const override;
118 ANIMGRAPHRUNTIME_API virtual bool SetIgnoreForRelevancyTest(bool bInIgnoreForRelevancyTest) override;
119 ANIMGRAPHRUNTIME_API virtual float GetCachedBlendWeight() const override;
120 ANIMGRAPHRUNTIME_API virtual void ClearCachedBlendWeight() override;
121 ANIMGRAPHRUNTIME_API virtual const FDeltaTimeRecord* GetDeltaTimeRecord() const override;
122 // End of FAnimNode_RelevantAssetPlayerBase
123
124private:
125 // Return the index of the next FRandomPlayerSequenceEntry to play, from the list
126 // of valid playable entries (ValidEntries).
127 int32 GetNextValidEntryIndex();
128
129 // Return the play data for either the currently playing animation or the next
130 // animation to blend into.
131 FRandomAnimPlayData& GetPlayData(ERandomDataIndexType Type);
132 const FRandomAnimPlayData& GetPlayData(ERandomDataIndexType Type) const;
133
134 // Initialize the play data with the given index into the ValidEntries array and
135 // a specific blend weight. All other member data will be reset to their default values.
136 void InitPlayData(FRandomAnimPlayData& Data, int32 InValidEntryIndex, float InBlendWeight);
137
138 // Advance to the next playable sequence. This is only called once a sequence is fully
139 // blended or there's a hard switch to the same playable entry.
140 void AdvanceToNextSequence();
141
142 // Build a new ShuffleList array, which is a shuffled index list of all the valid
143 // playable entries in ValidEntries. The LastEntry can be set to a valid entry index to
144 // ensure that the top/last item in the shuffle list will be a different value from it;
145 // pass in INDEX_NONE to disable the check.
146 void BuildShuffleList(int32 LastEntry);
147
148 // List of valid sequence entries
149 TArray<FRandomPlayerSequenceEntry*> ValidEntries;
150
151 // Normalized list of play chances when we aren't using shuffle mode
152 TArray<float> NormalizedPlayChances;
153
154 // Play data for the current and next sequence
155 TArray<FRandomAnimPlayData> PlayData;
156
157 // Index of the 'current' data set in the PlayData array.
158 int32 CurrentPlayDataIndex;
159
160 // List to store transient shuffle stack in shuffle mode.
161 TArray<int32> ShuffleList;
162
163 // Random number source
165
166#if WITH_EDITORONLY_DATA
167 // If true, "Relevant anim" nodes that look for the highest weighted animation in a state will ignore this node
168 UPROPERTY(EditAnywhere, Category = Relevancy, meta = (FoldProperty, PinHiddenByDefault))
169 bool bIgnoreForRelevancyTest = false;
170#endif // WITH_EDITORONLY_DATA
171
172protected:
174 UPROPERTY(BlueprintReadWrite, Transient, Category = DoNotEdit)
175 float BlendWeight = 0.0f;
176
177public:
182 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings")
183 bool bShuffleMode;
184};
ERandomDataIndexType
Definition AnimNode_RandomPlayer.h:15
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition Array.h:670
Definition AnimSequenceBase.h:37
Definition AnimationAsset.h:1020
Definition AlphaBlend.h:71
Definition AnimNode_RelevantAssetPlayerBase.h:14
Definition AnimNode_RandomPlayer.h:97
Definition AnimNodeBase.h:324
Definition AnimNodeBase.h:354
Definition AnimationAsset.h:98
Definition AnimationAsset.h:67
Definition AnimNodeBase.h:642
Definition AnimNodeBase.h:479
Definition AnimNode_RandomPlayer.h:68
FMarkerTickRecord MarkerTickRecord
Definition AnimNode_RandomPlayer.h:92
FDeltaTimeRecord DeltaTimeRecord
Definition AnimNode_RandomPlayer.h:80
Definition AnimNode_RandomPlayer.h:25
Definition RandomStream.h:20
Definition ObjectPtr.h:488