5#include "CoreMinimal.h"
6#include "Kismet/GameplayStatics.h"
7#include "GameFramework/PlayerInput.h"
8#include "Engine/EngineTypes.h"
9#include "Input/Events.h"
12#include "Runtime/CoreUObject/Public/UObject/Class.h"
13#include "Runtime/CoreUObject/Public/UObject/UObjectGlobals.h"
14#include "Runtime/CoreUObject/Public/UObject/Package.h"
15#include "UObject/CoreOnline.h"
16#include "BehaviorTree/BehaviorTreeTypes.h"
17#include "ProjectXGameplayStatics.generated.h"
19DECLARE_CYCLE_STAT(TEXT(
"UProjectXGameplayStatics::GetAllObjectsImplementingInterfaceFastPath"), STAT_GetAllObjectsImplementingFastPath, STATGROUP_PROJECTY);
21class AProjectXPlayerCharacterBase;
25class UBlackboardComponent;
31 GENERATED_USTRUCT_BODY()
34 TWeakObjectPtr<AActor> ActorToDamage =
nullptr;
49 UFUNCTION(BlueprintCallable, Category =
"UI", meta = (WorldContext =
"WorldContextObject"))
50 static UAdvancedUserWidget* FindOrCreateAdvancedUserWidget(
const UObject* WorldContextObject,
const TSubclassOf<class UAdvancedUserWidget> AdvancedUserWidget,
const int32 ZOrder );
51 UFUNCTION(BlueprintPure, Category =
"UI", meta = (WorldContext =
"WorldContextObject"))
52 static UAdvancedUserWidget* GetCurrentlyOpenAdvancedUserWidget(
const UObject* WorldContextObject);
53 UFUNCTION(BlueprintPure, Category =
"UI", meta = (WorldContext =
"WorldContextObject"))
55 UFUNCTION(BlueprintPure, Category =
"UI", meta = (WorldContext =
"WorldContextObject"))
57 UFUNCTION(BlueprintPure, Category =
"UI", meta = (WorldContext =
"WorldContextObject"))
58 static FString GetWidgetPath(
const UWidget*
Widget);
60 UFUNCTION(BlueprintPure)
61 static UObject* GetDefaultObject(
const UClass*
Class);
63 UFUNCTION(BlueprintPure)
64 static int64 GetUniqueID(const UObject* Object) {
return Object ? Object->GetUniqueID() : INDEX_NONE; }
67 static void SetTimer(
const UObject* WorldContextObject, FTimerDelegate
const& InDelegate,
const float Time,
const bool bLoop =
false);
69 UFUNCTION(BlueprintPure, Category =
"Math Helpers")
70 static
void GetSocketTransformRelativeToRoot(FName Socket, USkeletalMeshComponent* SkeletalMesh, FTransform& OutTransform);
73 UFUNCTION(BlueprintPure, Category = "Math Helpers")
74 static
float SmoothStep(
float A,
float B,
float X);
76 UFUNCTION(BlueprintPure, Category = "Math Helpers")
77 static
float InverseLerp(
float A,
float B,
float X,
bool bClamped = true);
78 UFUNCTION(BlueprintPure, Category = "Math Helpers")
79 static FVector VRandRange(const FVector& A, const FVector& B);
80 UFUNCTION(BlueprintPure, Category = "Math Helpers")
81 static FVector2D VRandRange2D(const FVector2D& A, const FVector2D& B);
82 UFUNCTION(BlueprintPure, Category = "Math Helpers")
83 static FVector GetRandomPointInActorBounds(const AActor* Actor);
84 UFUNCTION(BlueprintPure, Category = "Math Helpers")
85 static FBox GetFBoxFromActorBounds(const AActor* Actor);
86 static
bool GetValidSpawnLocationAroundTarget(const
AProjectXPlayerState* TestInstigator, const AActor* TargetActor, FTransform& OutTransform,
int SearchSteps = 10,
float DistanceFromTarget = 1024.f,
float UpwardsPlacementOffset = 150.f);
88 UFUNCTION(BlueprintPure, Category = "Camera Info")
89 static TArray<FVector> GetCameraFrustumPoints(const UCameraComponent* const Camera);
91 UFUNCTION(BlueprintPure, Category = "
General Helpers", meta = (WorldContext = "WorldContextObject"))
92 static
void GetActorComponents(const UObject* WorldContextObject, const TSubclassOf<UActorComponent> TypeFilter, TArray<UActorComponent*>& Components);
94 UFUNCTION(BlueprintPure, Category = "
General Helpers")
95 static UTexture2D* GetPlayerAvatar(const FString& PlayerID);
96 UFUNCTION(BlueprintPure, Category = "
General Helpers")
97 static FString GetPlayerUserName(const FString& PlayerID);
98 UFUNCTION(BlueprintPure, Category = "
General Helpers")
99 static FString GetPlayerID(UPARAM(ref)FUniqueNetIdRepl& NetID);
100 UFUNCTION(BlueprintCallable, Category = "
General Helpers")
101 static
void CopyToClipboard(const FString& ToCopy);
103 UFUNCTION(BlueprintCallable)
104 static
void SpaceText(UPARAM(ref) FText& Text);
106 UFUNCTION(BlueprintPure, Category = "Material Helpers")
107 static UMaterialInstance* GetPostProcessMaterial(class UPostProcessComponent* PostProcess, const int32 Index);
108 UFUNCTION(BlueprintPure, Category = "Material Helpers")
109 static UMaterialInstanceDynamic* GetPostProcessMaterialDynamic(UPostProcessComponent* PostProcess, const int32 Index);
110 UFUNCTION(BlueprintCallable, Category = "Material Helpers")
111 static
void SetPostProcessMaterialScalarParameter(UPostProcessComponent* PostProcess, const int32 Index, const FName& ParamName, const
float Value);
112 UFUNCTION(BlueprintCallable, Category = "Material Helpers")
113 static
void SetPostProcessMaterialVectorParameter(UPostProcessComponent* PostProcess, const int32 Index, const FName& ParamName, const FLinearColor& Value);
114 UFUNCTION(BlueprintCallable, Category = "Material Helpers")
115 static
void SetPostProcessTextureParameter(UPostProcessComponent* PostProcess, const int32 Index, const FName& ParamName, UTexture* const Texture);
116 UFUNCTION(BlueprintPure, Category = "Material Helpers")
117 static FLinearColor GetPostProcessMaterialVectorParameter(UPostProcessComponent* PostProcess, const int32 Index, const FName& ParamName);
118 UFUNCTION(BlueprintPure, Category = "Material Helpers")
119 static
float GetPostProcessMaterialScalarParameter(UPostProcessComponent* PostProcess, const int32 Index, const FName& ParamName);
120 UFUNCTION(BlueprintCallable, Category = "PostProcess Settings Helpers")
121 static
void ModifyAmbientCubemapTint(APostProcessVolume* PostProcess, FLinearColor NewColor);
122 UFUNCTION(BlueprintCallable, Category = "PostProcess Settings Helpers")
123 static
void ModifyAmbientCubemapIntensity(APostProcessVolume* PostProcess,
float NewValue);
125 UFUNCTION(BlueprintCallable, Category = "Mesh Helpers")
126 static
void CreatePoseableMeshFromMeshComponent(AActor* Owner, USceneComponent* RootComponent, EAttachmentRule AttachmentRules, const TArray<UMeshComponent*>& MeshComponents);
128 UFUNCTION(BlueprintPure, Category = "Animation Helpers")
129 static
void ScaleAnimationToTime(UAnimMontage*& Montage, const
float Time);
130 UFUNCTION(BlueprintPure, Category = "Animation Helpers")
131 static
float GetScaledAnimationTime(const UAnimMontage* Montage, const
float Time);
132 UFUNCTION(BlueprintPure, Category = "Audio Queries")
133 static
float GetAudioComponentFloatParam(const UAudioComponent* Component, const FName ParamName);
135 static
void MakeJSONStringFromString(FString& Output, const FString& FieldName,const FString& Entry);
136 static
void MakeJSONStringFromInt(FString& Output, const FString& FieldName,
int Entry);
138 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
139 static FName GetActionKeyName(const UObject* WorldContextObject, const FName ActionName, const
float BindScale = 0);
140 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
141 static UTexture2D* GetPlatformKeyIcon(const UObject* WorldContextObject, FName Keyname);
142 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
143 static UTexture2D* GetGamepadPlatformKeyIcon(const UObject* WorldContextObject, FName Keyname);
144 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
145 static
void GetKeysForAction(UObject* WorldContextObject, FName ActionName, TArray<FInputActionKeyMapping>& Bindings);
146 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
147 static
bool KeyMatchesAction(UObject* WorldContextObject, FName ActionName, const FKeyEvent& KeyEvent);
148 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
149 static FName GetActionForKey(UObject* WorldContextObject, const FKeyEvent& KeyEvent);
150 UFUNCTION(BlueprintCallable, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
151 static
bool SetFocusOnFirstFocuseableChild(class UUserWidget*
Widget);
152 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
153 static
bool IsUsingGamePad(const UObject* WorldContextObject);
154 UFUNCTION(BlueprintPure, Category = "
Input Queries", meta = (WorldContext = "WorldContextObject"))
155 static FName GetActionNameForKey(const FKey& Key);
156 static
void OpenLevel(const UObject* WorldContextObject, FName LevelName,
bool bAbsolute = true, FString Options = FString(TEXT("")));
162 UFUNCTION(BlueprintPure, Category = "Utilities|String")
163 static FString PXTimeSecondsToString(
float InSeconds);
165 UFUNCTION(BlueprintCallable, Category = "Helpers")
166 static
void ClearAllTimersForObject(const UObject* Object);
168 UFUNCTION(BlueprintPure, Category = "System Info")
169 static
bool IsEditor() {
return WITH_EDITOR; };
170 UFUNCTION(BlueprintPure, Category =
"System Info")
172 UFUNCTION(BlueprintPure, Category =
"System Info")
174 UFUNCTION(BlueprintPure, Category =
"System Info")
176 UFUNCTION(BlueprintPure, Category =
"System Info")
178 UFUNCTION(BlueprintPure, Category =
"System Info")
180 UFUNCTION(BlueprintPure, Category =
"System Info")
181 static
bool IsShippingBuild() {
return UE_BUILD_SHIPPING; }
182 UFUNCTION(BlueprintPure, Category =
"System Info")
184 UFUNCTION(BlueprintPure, Category =
"System Info")
185 static
bool IsPS4() {
return PLATFORM_PS4; }
186 UFUNCTION(BlueprintPure, Category =
"System Info")
187 static
bool IsXboxOne() {
return PLATFORM_XBOXONE; }
189 static void CleanupCharacterForServer(ACharacter* Character,
bool bRemoveCharacterMesh =
true);
191 UFUNCTION(BlueprintCallable, Category =
"Post Process")
192 static
void AddOrUpdateBlendableOnTarget(AActor* Target, TScriptInterface<IBlendableInterface> InBlendableObject,
float InWeight);
193 UFUNCTION(BlueprintCallable, Category = "Post Process")
194 static
void RemoveBlendableOnTarget(AActor* Target, TScriptInterface<IBlendableInterface> InBlendableObject);
196 UFUNCTION(BlueprintPure, Category = "Post Process")
197 static
bool IsValidVersion(
int VersionNumberIn,
int BranchNumberIn);
199 UFUNCTION(BlueprintPure, Category = "AI Helpers", meta = (WorldContext = "WorldContextObject"))
200 static
void GetAllAliveTargets(const UObject* WorldContextObject, TArray<AActor*>& TargetableActors,
bool bTargetAllies = false);
201 UFUNCTION(BlueprintPure, Category = "AI Helpers", meta = (WorldContext = "WorldContextObject"))
202 static
void GetTargetsInRadius(const UObject* WorldContextObject, const FVector& StartLocation,
float Radius, TArray<AActor*>& Targets);
203 static FVector ResolveBlackboardKeySelectorToVector(struct FBlackboardKeySelector BlackboardKeySelector, const UBlackboardComponent* BlackboardComponent);
205 UFUNCTION(BlueprintPure, Category = "AI Helpers", meta = (WorldContext = "WorldContextObject"))
206 static
bool IsPathable(const UObject* WorldContextObject, const FVector& EndPosition, const FVector& StartPosition, TSubclassOf<AActor> NavAgentClass);
207 UFUNCTION(BlueprintPure, Category = "AI Helpers", meta = (WorldContext = "WorldContextObject"))
208 static
bool ProjectPointToNavigation(const UObject* WorldContextObject, FVector& Point, TSubclassOf<AActor> NavAgentClass, FVector Extents);
217 UFUNCTION(BlueprintCallable, Category = Collision)
218 static
bool GetClosestPointOnCollision(const AActor* Actor, const FVector& Point, const ECollisionChannel& Channel, FVector& ClosestPoint);
219 static
bool GetClosestPointOnCollision(const AActor* Actor, const FVector& Point, const ECollisionChannel& Channel, FVector& ClosestPoint, UPrimitiveComponent** ClosestComponent);
221 static
void AddDamageAffliction(AActor* Victim, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser);
224 UFUNCTION(BlueprintCallable)
225 static
bool IsCDO(const UObject* const Object) {
return Object && ((Object->GetFlags() & RF_ClassDefaultObject) == 0 && (Object->GetFlags() & RF_ArchetypeObject) == 0); }
227 UFUNCTION(BlueprintCallable)
228 static FVector2D GetActorSizeOnScreen(APlayerController* PlayerController, AActor* Actor,
bool bOnlyCollidingComponents,
bool bIgnoreQueryOnlyComponents =
false);
229 UFUNCTION(BlueprintCallable)
230 static FVector2D GetActorSizeOnScreenProjection(APlayerController* PlayerController, AActor* Actor,
bool bOnlyCollidingComponents,
bool bIgnoreQueryOnlyComponents =
false);
231 UFUNCTION(BlueprintCallable)
232 static FVector2D GetActorScreenPercentage(APlayerController* PlayerController, AActor* Actor,
bool bOnlyCollidingComponents,
bool bIgnoreQueryOnlyComponents =
false);
235 static
bool GetPenetrationAdjustment(UWorld const* World, AActor const* TestActor, UPrimitiveComponent const* PrimComp, FTransform const& TestWorldTransform, FVector& OutProposedAdjustment, const TArray<AActor*>& IgnoreActors);
238 UE_DEPRECATED(4.26, "This function is deprecated. Please use PXApplyRadialDamageWithFalloff instead.")
239 UFUNCTION(BlueprintCallable, Category = "
Damage", meta=(DeprecatedFunction, DeprecationMessage="Function has been deprecated, Please use PXApplyRadialDamageWithFalloff"))
240 static
float ApplyRadialDamageSingle(AActor* Target,
float BaseDamage,
float MinimumDamage, const FVector& Origin,
float DamageInnerRadius,
float DamageOuterRadius,
float DamageFalloff, TSubclassOf<class UDamageType> DamageTypeClass, AActor* DamageCauser, AController* InstigatedByController);
242 UFUNCTION(BlueprintPure, Category = "
Damage")
243 static FDamageEvent MakeDamageEventFromClass(TSubclassOf<UDamageType> DamageType);
244 UFUNCTION(BlueprintCallable, Category = "
Damage", meta = (WorldContext = "WorldContextObject"))
245 static
float PXApplyRadialDamageWithFalloff(const UObject* WorldContextObject, const class
UWeaponInstance* WeaponInstance,
float BaseDamage,
float MinimumDamage, const FVector& Origin,
float DamageInnerRadius,
float DamageOuterRadius,
float DamageFalloff, TSubclassOf<class UDamageType> DamageTypeClass, const TArray<AActor*>& IgnoreActors, TArray<AActor*>& OutHitActors, AActor* DamageCauser, AController* InstigatedByController, ECollisionChannel DamagePreventionChannel,
bool bActorsInRadiusAsIgnoredActors = true,
bool bIgnoreAllies = false);
246 static
bool ActorIsDamageableFrom(AActor* Victim, FVector const& Origin, const TArray<AActor*>& IgnoreActors, ECollisionChannel TraceChannel, FHitResult& OutHitResult,
float MaxDistanceAllowed, UPrimitiveComponent* ClosestComponent =
nullptr);
249 UFUNCTION(BlueprintCallable, meta=(AdvancedDisplay = "3", WorldContext = "WorldContextObject", CallableWithoutWorldContext))
250 static
void PlayLocalSound(const UObject* WorldContextObject, USoundBase* Sound,
float VolumeMultiplier = 1.f,
float PitchMultiplier = 1.f,
float StartTime = 0.f, USoundConcurrency* ConcurrencySettings =
nullptr, AActor* OwningActor =
nullptr);
252 UFUNCTION(BlueprintCallable, meta=(DeterminesOutputType="InObjectArray", DynamicOutputParam="ObjectArray"))
253 static
void SortObjects(const TArray<UObject*>& InObjectArray, TArray<UObject*>& ObjectArray, FDelegateSortObject Condition);
255 UFUNCTION(BlueprintPure, Category = "Queries", meta = (WorldContext = "WorldContextObject"))
256 static
void GetAllObjectsImplementingInterface(const UObject* WorldContextObject, TSubclassOf<class UInterface> Interface, TArray<UObject*>& Objects);
257 UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "3", WorldContext = "WorldContextObject", CallableWithoutWorldContext))
258 static
bool IsAnnouncerSpeaking(const UObject* WorldContextObject);
259 UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "3", WorldContext = "WorldContextObject", CallableWithoutWorldContext))
260 static
void PlayAnnouncerVoice(const UObject* WorldContextObject, FString const VoiceToPlay);
263 static
void GetAllObjectsImplementingInterface(const UObject* WorldContextObject, TArray<UObject*>& Objects)
265 SCOPE_CYCLE_COUNTER(STAT_GetAllObjectsImplementingFastPath)
266 UWorld*
const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
272 for (TObjectIterator<T> Itr; Itr; ++Itr)
280 template<
typename TEnum>
283 const UEnum* enumPtr = FindObject<UEnum>(ANY_PACKAGE, *Name,
true);
286 return FString(
"Invalid");
288 int32 Index = enumPtr->GetIndexByValue((int64)Value);
289 FText EnumText = enumPtr->GetDisplayNameTextByIndex(Index);
290 FString Output = EnumText.ToString();
291 Output.RemoveSpacesInline();
292 return MoveTemp(Output);
295 template<
typename TEnum>
298 const UEnum* enumPtr = FindObject<UEnum>(ANY_PACKAGE, *Name,
true);
301 return TEnum((uint8)0);
304 int32 Index = enumPtr->GetIndexByNameString(Value);
305 TEnum Output = TEnum((uint8)Index);
312 const int32 BuffTypeMask = (1 << (int32)Enum);
313 return (Data & BuffTypeMask) != 0;
319 UWorld*
const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
325 TArray<AActor*> FoundActors;
326 GetAllActorsOfClass(World, T::StaticClass(), FoundActors);
327 if (FoundActors.Num() > 0)
329 return Cast<T>(FoundActors[0]);
332 FActorSpawnParameters SpawnParameters;
333 SpawnParameters.bNoFail =
true;
334 SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
336 return World->SpawnActor<T>(SpawnParameters);
342 for (int32 i = Deck.Num() - 1; i >= 0; i--)
344 const int32 j = FMath::RandRange(i, Deck.Num() - 1);
345 T temp = MoveTemp(Deck[i]);
346 Deck[i] = MoveTemp(Deck[j]);
347 Deck[j] = MoveTemp(temp);
354 return Array.Num() > 0 ? Array[FMath::RandRange(0, Array.Num() - 1)] :
nullptr;
360 Mask |= 1 << (int32)Flag;
365 Mask &= ~(1 << (int32)Flag);
370 return ((Mask & 1 << (int32)Flag) > 0);
#define IS_CONSOLE_PLATFORM
Definition: ProjectX.h:84
#define VALIDATE_OBJECT_ITERATOR(c, w, v)
Definition: ProjectX.h:90
EBuildType
Definition: ProjectX.h:28
@ Release
Definition: TelekenesisComponent.cpp:166
DECLARE_DYNAMIC_DELEGATE_ThreeParams(FDelegateSortObject, const UObject *, A, const UObject *, B, bool &, Result)
DECLARE_CYCLE_STAT(TEXT("UProjectXGameplayStatics::GetAllObjectsImplementingInterfaceFastPath"), STAT_GetAllObjectsImplementingFastPath, STATGROUP_PROJECTY)
#define BRANCH_BUILD
Definition: ProjectXVersion.h:5
#define GAME_BUILT_VERSION
Definition: ProjectXVersion.h:4
Definition: ProjectXPlayerState.h:238
Definition: ProjectXGameplayStatics.h:45
static T GetRandomArrayIndex(const TArray< T > &Array)
Definition: ProjectXGameplayStatics.h:352
static TEnum GetEnumValueFromString(const FString &Name, FString Value)
Definition: ProjectXGameplayStatics.h:296
static void ClearFlag(int32 &Mask, T Flag)
Definition: ProjectXGameplayStatics.h:363
static bool HasFlag(int32 &Mask, T Flag)
Definition: ProjectXGameplayStatics.h:368
static bool HasEnumBitFlag(T Enum, int32 Data)
Definition: ProjectXGameplayStatics.h:310
static void Shuffle(TArray< T > &Deck)
Definition: ProjectXGameplayStatics.h:340
static void SetFlag(int32 &Mask, T Flag)
Definition: ProjectXGameplayStatics.h:358
static FString GetEnumValueToString(const FString &Name, TEnum Value)
Definition: ProjectXGameplayStatics.h:281
static T * FindOrSpawnSingleton(const UObject *WorldContextObject)
Definition: ProjectXGameplayStatics.h:317
Definition: WeaponInstance.h:220
Definition: ProjectXGameplayStatics.h:30
FHitResult DamagedActorHitResult
Definition: ProjectXGameplayStatics.h:36
FRadialDamageEvent RadialDamageEvent
Definition: ProjectXGameplayStatics.h:38