BlueprintNativeEvent Crash - What am I doing wrong?

I’ve implemented a blueprint native event in the game mode.
Unreal Engine 5.0.3 source build.

on the .h file"

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Somthing")
void HandleSomthing();
virtual void HandleSomthing_Implementation();

Then on the .cpp file:

void ASomeGameMode::HandleSomthing_Implementation()
{
	// Do some things...

	// Call BP event
	HandleSomthing();

	// Do some other things...
}

Every time HandleSomthing(); is called from the c++ and the event is not implemented on the game mode blueprint - a crash is happening.

As long as I override the game mode blueprint event with anything (even empty - just need the red event node on the graph) it’s all ok.

Am I doing something wrong or this is a new bug? (I don’t remember this behaviour)

Thanks.

In general with Blueprint Native Events, when you call the base function, so in your case HandleSomething from C++, it will automatically call the Implementation, but first it will try to call the implementation that’s overridden inside your blueprints, so you don’t have to call that yourself. If you ever do want to add logic to your blueprint overridden native event, just add your logic, but remember to call the parent function, which will run the C++ code

My example:

And just for showing how it would work, if I override it in BP:

The parent node is basically the C++ code. When I call OnDamageReceived from C++, it will find the function if it’s overridden in BP, and call that first ignoring the C++ code, unless I call the parent function inside the BP

if I’m not mistaken, not overriding your function in BP will cause an infinite loop, because calling HandleSomthing will first search in the BP to run that implementation, but if that doesn’t exist then it will run the _Implementation C++ function, which calls itself in its body thus creating a loop, and crashing

So to sum up:

  • Blueprint native events will call the Blueprint function first, if it exists. Unreal handles that automatically
  • Never call the _Implementation directly, unless in the form of Super::Something_Implementation() inside the body of a C++ overridden implementation
  • Treat the native event as any other function, which means that inheritance works the same way. If you override a Native Event in blueprint, the C++ function is the “Super”, or in BP language the parent. If you override the event in an inheriting blueprint, then you once again need to call the parent if that’s what you need. The parent in that case would be the parent blueprint event implementation
2 Likes

Thank you so much for that great answer!

I’ve accidentally called the _Implementation without realizing the side effects.

1 Like