Blueprint event not finishing before continuing with C++ code

In the code below, the issue I’m having is that EndConversation() gets called before HandleDisplayNPCResponse() returns.

I’m working on a conversation system. I basically need the NPC’s dialogue to be displayed and allow the NPC enough time to complete speaking its line before continuing along in the code.


//End of conversation?
if (NPCResponse.bForceConversationEnd)

HandleDisplayNPCResponse() is a BlueprintImplementableEvent. HandleDisplayNPCResponse is in charge of displaying the words of the NPC and delaying until the NPC is finished speaking. EndConversation is in charge of concluding the conversation and calling another BlueprintImplementableEvent which cleans up the UI.

There is a delay node in the DisplayNPCResponse and a print statement to confirm when the function is finished. However at the end of a conversation, the UI always gets removed by EndConversation() before the NPC response is finished displaying.

What is causing this? Is it just how Blueprint Events are handled?

As you might have noted events in BP are able to handle what is called a latent action, those actions will be delayed in time. If you use a delay node in your BP code of HandleDisplayNPCResponse the control flow will not wait for the whole event to finish, instead it will return to C++ as soon as a latent action is encountered. If not your whole game would block.

What you normally do in those cases is call back into C++ from your BP code, this way you start the event in C++, execute all your required control logic in BP and once you have finished you call back into C++ triggering the end of your conversation.

Awesome thank you. So if I do not use a delay, does this ensure that an event will completely finish before the code execution continues?

it does but not 100%, BP event execution can halt if the system decides to, so the rule is do not rely on events to finish directly, I prefer calling back into C++ or using delegates. Remember to resolve the issue ^^