// Copyright 2025 https://yuewu.dev/en All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "GameplayEffectTypes.h" #include "Runtime/Launch/Resources/Version.h" #if ENGINE_MINOR_VERSION < 5 #include "InstancedStruct.h" #else #include "StructUtils/InstancedStruct.h" #endif #include "GGA_GameplayEffectContext.generated.h" /** * */ USTRUCT() struct GENERICGAMEPLAYABILITIES_API FGGA_GameplayEffectContext : public FGameplayEffectContext { GENERATED_BODY() virtual FGameplayEffectContext* Duplicate() const override; virtual UScriptStruct* GetScriptStruct() const override; virtual bool NetSerialize(FArchive& Ar, UPackageMap* Map, bool& bOutSuccess) override; TArray& GetPayloads(); void AddOrOverwriteData(const FInstancedStruct& DataInstance); const FInstancedStruct* FindPayloadByType(const UScriptStruct* PayloadType) const; FInstancedStruct* FindPayloadByType(const UScriptStruct* PayloadType); FInstancedStruct* FindOrAddPayloadByType(const UScriptStruct* PayloadType); FInstancedStruct* AddPayloadByType(const UScriptStruct* PayloadType); bool RemovePayloadByType(const UScriptStruct* PayloadType); /** Find payload of a specific type in this context (mutable version). If not found, null will be returned. */ template T* FindMutablePayloadByType() { if (FInstancedStruct* FoundData = FindPayloadByType(T::StaticStruct())) { return FoundData->GetMutablePtr(); } return nullptr; } /** Find payload of a specific type in this context. If not found, null will be returned. */ template const T* FindPayload() const { if (const FInstancedStruct* FoundData = FindPayloadByType(T::StaticStruct())) { return FoundData->GetPtr(); } return nullptr; } /** Find payload of a specific type in this context. If not found, a new default instance will be added. */ template const T& FindOrAddPayload() { if (const T* ExistingData = FindPayload()) { return *ExistingData; } FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct()); return NewData->Get(); } /** Find payload of a specific type in this context. (mutable version). If not found, a new default instance will be added. */ template T& FindOrAddMutablePayload() { if (T* ExistingData = FindMutablePayloadByType()) { return *ExistingData; } FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct()); return NewData->GetMutable(); } template T* FindOrAddMutablePayloadPtr() { if (T* ExistingData = FindMutablePayloadByType()) { return ExistingData; } FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct()); return NewData->GetMutablePtr(); } protected: UPROPERTY() TArray Payloads; }; template <> struct TStructOpsTypeTraits : TStructOpsTypeTraitsBase2 { enum { WithNetSerializer = true, WithCopy = true }; };