[Answered - partly] Waiting in a C++ function in Blueprint

I am writing my own CreateSession in C++ so our blueprints can use it and set things like the name, and settings on it.

I need to have the blueprint run the MyCreateSession node, and have blueprint outputs Success and Failure.

The requires that I call IOnlineSession::CreateSession() with some parameters in C++ and then wait until the
callback comes in that it is created (or fails) and then continue the blueprint script
with the two outputs.

Extensive Googeling does not show an example of this.

  • How do you return two output branches such as Success and Failure from a blueprint function?

  • How do I do a ‘yield’, ‘sleep’, or ‘wait’ in a blueprint script in C++ ?

u can take a look at how they do their create session node in source code, it kind of complicated to do and plus u need to make your own custom node for that. I recommend do you node and have 2 Blueprint Implement event when create session finish.
For the sleep and wait u can use FPlatformProcess::Sleep(time); but it will freeze your main thread so better use GetWorldTimerManager().SetTimer

ANSWER - Ok, so the basic process for this type of question on blueprints is two fold:

  • Go to GitHub and download the Unreal Engine source. (And maybe the Tournament Source too).
  • In blueprints if you right clik to get the menu on a node (box) one of the menu items is Goto Code Definition. This will open Visual Studio to the .h file for the node. You have to do a Ctrl-F and find the functions def in VS. Then you can go in the Unreal SOurce code and find the matching .cpp file, and you have source for every node in blueprints.

More to the direct question: Making blueprint nodes wait until some background action is done, like CreateSession, then wait for the OnSessionCreated in C++ code as a delegate (callback) requires you to make a C++ custom node. (I have not yet actualy implementd such a beast, Here there be dragons.) But you have the full source to CreateSession for esample. Either copy, or sub-class, not sure which is better.

I think one can also do the whole thing in blueprint nodes by defining some event thingys.