Hey, as the title says, I’ve tried creating a callback using UE4 delegates, however, before that I tried using a normal C++ function pointer. The memory is always valid when trying to execute the callback pointer, but it just won’t run.
Vital declarations in my header
typedef void(ATriggerActor::*VoidFuncPtrNoParams)(void);
DECLARE_DELEGATE(FOnCompletionCB)
FOnCompletionCB OnCompletionCB;
Setting up the Callback
void UTriggerOptionBase::SetUpCompletionCallback(ATriggerActor* CallbackOwner, VoidFuncPtrNoParams CallbackFunc)
{
OnCompletionCB.BindRaw(CallbackOwner, CallbackFunc);
}
Trying to execute the delegate
void UTriggerOptionProxy::StartTriggerOption()
{
OnCompletionCB.ExecuteIfBound();
}
Notes
-
UTriggerOptionProxy is derived from UTriggerOptionBase
-
I’ve tried binding the delegate with a shared pointer, same result.
-
Also tried doing the callback with a normal C++ func pointer, which oddly enough didn’t work either. I tried to replicate the normal func pointer issue outside of an UE project, but I couldnt do it, it worked no matter how I threw it around.
-
The method I’m trying to execute is a private member method of UTriggerOptionProxy (UTriggerOptionBase), however, that shouldn’t matter since I’ve got the proper access when I’m setting up the callback since I’m calling it from
ATriggerActor::BeginPlay
toUTriggerOptionProxy(UTriggerOptionBase)::SetUpCompletionCallback
, thus getting proper access and memory.
If you want to see how I tried reproducing the function pointer issue outside of Unreal.
Any ideas? Would be greatly appreciated!