November 29, 2017

Debugging UFunction::Invoke

By Nick Darnell

Back in October Nick Penwarden highlighted several improvements that we made to Unreal Engine 4 while working on Fortnite Battle Royale.

One of the things that didn't make the list in his article is a little debugging gem I added while working on Battle Royale. The team made heavy use of Blueprint based Widgets so we would often see callstacks in C++ like the following, which don’t capture who in Blueprints is actually making the native call.

 
[Your C++ Code]
UFunction::Invoke(...)  
UObject::ProcessEvent(...)  
AActor::ProcessEvent(...)  
[Rest of the stack]

I was working with a lot of code in Fortnite that I was unfamiliar with, so it wasn't always obvious where the calls might be coming from. To aid in my search I added a C command you can run from the Immediate Window in Visual Studio that will print the current Blueprint/Scripting callstack.

When running an Editor build of your game, you can now use the command,

{,,UE4Editor-Core}::PrintScriptCallstack()

and just
::PrintScriptCallstack() 

in a monolithic build when using 4.18 and beyond.
770_DebuggingUFunction_Invoke.jpg

I hope you find this as useful as I have in getting a live snapshot of the callstacks in your UE4 projects.