Skip to content

Commit

Permalink
Fix overlapping activations in multiplayer PIE
Browse files Browse the repository at this point in the history
  • Loading branch information
landelare committed Aug 14, 2024
1 parent a284220 commit 5bfd7e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
24 changes: 23 additions & 1 deletion Source/UE5CoroGAS/Private/UE5CoroGameplayAbility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

using namespace UE5Coro;
using namespace UE5Coro::Private;
using namespace UE5CoroGAS::Private;

namespace
{
Expand Down Expand Up @@ -79,10 +80,31 @@ FMulticastDelegateProperty* FindDelegate(UClass* Class)
}
}

namespace UE5CoroGAS::Private
{
struct FStrictPredictionKey : FPredictionKey
{
FStrictPredictionKey(const FPredictionKey& Key) noexcept
: FPredictionKey(Key) { }

bool operator==(const FStrictPredictionKey& Other) const noexcept
{
return FPredictionKey::operator==(Other) && Base == Other.Base;
}
};
static_assert(sizeof(FStrictPredictionKey) == sizeof(FPredictionKey));

int32 GetTypeHash(const FStrictPredictionKey& Key) noexcept // ADL
{
return GetTypeHash(static_cast<const FPredictionKey&>(Key)) ^
Key.Base << 16;
}
}

UUE5CoroGameplayAbility::UUE5CoroGameplayAbility()
{
if (::IsTemplate(this))
Activations = new TMap<FPredictionKey, TAbilityPromise<ThisClass>*>;
Activations = new TMap<FStrictPredictionKey, TAbilityPromise<ThisClass>*>;
else
Activations = GetDefault<ThisClass>(GetClass())->Activations;
checkf(Activations, TEXT("Internal error: non-template object before CDO"));
Expand Down
5 changes: 4 additions & 1 deletion Source/UE5CoroGAS/Public/UE5CoroGAS/UE5CoroGameplayAbility.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "UE5CoroGAS/AbilityPromise.h"
#include "UE5CoroGameplayAbility.generated.h"

namespace UE5CoroGAS::Private { struct FStrictPredictionKey; }

/** Usage summary:
* - Override ExecuteAbility with a coroutine instead of ActivateAbility
* - Call CommitAbility like usual, but do *NOT* call EndAbility
Expand All @@ -50,7 +52,8 @@ class UE5COROGAS_API UUE5CoroGameplayAbility : public UGameplayAbility

// One shared per class to support every instancing policy including derived
// classes changing their minds at runtime. The real one is on the CDO.
TMap<FPredictionKey, UE5Coro::Private::TAbilityPromise<ThisClass>*>* Activations;
TMap<UE5CoroGAS::Private::FStrictPredictionKey,
UE5Coro::Private::TAbilityPromise<ThisClass>*>* Activations;

public:
UUE5CoroGameplayAbility();
Expand Down

0 comments on commit 5bfd7e0

Please sign in to comment.