Problems creating a callback from an ActorComponent to an Actor. Tried binding delegates as SharedPointers, and Raw. Also tried C++ function pointers, memory looks good

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 to UTriggerOptionProxy(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!

I solved this after some time, and now I feel even more stupid. First correction was to BindUObject instead of SP or Raw, which is an easy miss if you’re new to UE4 delegates. However, after I fixed that I got another issue, and after some time I realised I hadn’t included the TriggerActor anywhere, it was just forward declared, hence why it wasn’t working …