I tried to reproduce this issue in a non Unreal Engine project, but I can’t seem to do it, so I’m quite unsure how to solve this, you can see how I [tried to reproduce it here.][1]
Anyhow, I’m trying to write a triggering gameplay system which works like this:
You have a trigger, can be anything, a volume trigger, a written button class which trigger something, a timed event or anything. That said trigger calls its trigger option class which only exists for the possibility of different usecases, some options at the top of my head: proxytrigger which instantly triggers, delayedtrigger which delays the trigger process, or something more complex like a trigger option that will only give you the OK sign if your health is 100%.
Once the TriggerOption tells the real Trigger that it’s been triggered, the TriggerAction will play, which can also be anything, a door opening perhaps? I wonder how many times I’ve said “trigger” by now … anyway, that’s the entire system. However, the process of TriggerOption telling TriggerActor (the actual trigger) that it should get triggered happens through a function pointer:
This is the function which sets up the function pointer:
void ATriggerActor::AttemptToTrigger()
{
if (!TriggerOption)
{
UE_LOG(LogTemp, Error, TEXT("TriggerOption is nullptr in TriggerActor: %s?"), *GetName());
return;
}
if (CanBeTriggered())
{
TriggerOption->StartTriggerOption(this, &ATriggerActor::OnTriggerOptionCompletedCB);
bHasBeenTriggered = true;
TriggerCount++;
}
}
This is the function that calls it, or stores it or whatever this subclass wants to do with it, in this case, it just calls it.
void UTriggerOptionProxy::StartTriggerOption(ATriggerActor* CallbackOwner, VoidFuncPtrNoParams CompletionCB)
{
(CallbackOwner->* (CompletionCB))();
}
This is also the typdef for the function pointer btw: typedef void(ATriggerActor::*VoidFuncPtrNoParams)(void);
When trying to call the function pointer,
, it throws this:
Exception thrown at 0x00007FF8A0954197 (UE4Editor-UE4Systems-3138.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
EDIT: Trying to fix the code format…