Hi folks,
I’m trying to create a static “SafeBind” function on my game manager that allows my custom classes to bind to a OnSoftReset delegate by passing the function as a paremeter, and if an instance of the game manager exists, it handles the binding/unbinding.
I’ve figured out (through Rider’s code tips) how to get it kind of working, but it only works on types of AActor, while I need it to work on all types.
The static function in my ASGameMode class (note: the Instance variable is set when the game starts, so I can always access ASGameMode with ASGameMode::Instance).
static bool SafeBindOnReset(AActor* Actor, TBaseDynamicDelegate<FWeakObjectPtr, void, AActor*>::TMethodPtrResolver<AActor>::FMethodPtr Handler, TEnumAsByte<ESDelegateAction> Action)
{
if (ASGameMode::Instance)
{
if (Action == Bind)
ASGameMode::Instance->OnSoftReset.AddDynamic(Actor, Handler);
else
ASGameMode::Instance->OnSoftReset.RemoveDynamic(Actor, Handler);
return true;
}
return false;
}
From my custom ASActor, I call:
ASGameMode::SafeBindOnReset(this, &ASActor::HandleSoftReset, Bind);
And I get an error saying it can’t convert from type void(ASActor::*)(AActor*)
to type void(AActor::*)(AActor*)
which I get, I’m just not sure how to make the function work regardless of type.
I know I could just check is ASGameMode::Instance is valid in my custom class and bind that way, but I recently discovered static functions and I’m kind of excited to experiment with stuff like this. Hoping someone can help me get this working.