How to bind event to event?

Hi! I want to bind event to event in C++ , how to do it?

I am trying this but but on clicking play button the engine crashed.

for (auto& Arr_Elem: PickupItems)
{
  Arr_Elem->Event_OnBeginOverlap.AddDynamic(this, &AMyClass::ExecBeginOverlap);
  Arr_Elem->Event_OnEndOverlap.AddDynamic(this, &AMyClass::ExecEndOverlap);
}

blueprint exmp

If this code compiles, it means you have declared the delegates and Binding to events ExecBeginOverlap and ExecEndOverlap functions have correct parameters in them.

If the engine crashes, it probably has something to do with null pointers, not the bindings themselves. Probably one or more of the array elements are nullptr, check them first before binding to events.

And if anything, test a more explicit for loop — use the actual class name instead of auto, like:
for (AMyPickupItem* item : PickupItems)

1 Like

I hve double checked, the array is not nulled, and I created native code from a working blueprint which looks like it.

MyOverLapDelegate.BindUFunction(this,FName(TEXT("ExecBeginOverlap")));
FCustomThunkTemplates::Array_Get(PickupItems, Array_Index, /*out*/ Array_Elements);
if(::IsValid(Array_Elements))
{
	Array_Elements->OnBeginOverlap.AddUnique(MyOverLapDelegate);
}