Executing and passing data between threads using a delegate call?

I have a UDP socket class that listens for outside server queries. The problem is that the engine UDP socket listener seems to be running in a different thread from the main thread. It’s not clear what’s happening, but I’m getting chaotic results as a result. In short, the UDP listener (internal to the engine) is calling my receiver delegate with the packet data, which in turn calls a second delegate which parses the received packet for display on the UI. The data is being passed using a TSharedPtr<> to pass the received packet between delegates. However, I imagine there’s some thread hopping going on here, so I’m fuzzy on the safety of passing the packet between delegates and even as to which thread the delegates are getting executed in. Could someone offer some insight to this?



AsyncTask(ENamedThreads::GameThread, =]()
{    
    // Code placed here will execute on game thread
});


Remember to include “Async.h” in your .cpp

too slow

Please enter a message with at least 10 characters (please_enter_message_x_chars)

I’ve shipped 4 Unreal products with C++ game code TCP connection to another process or PC.

Basically you just:

  • spin up your TCP server or client as usual and keep references in GameInstance so it persists through level loads
  • in Unreal … only read incoming messages and farm them out to World objects during GameMode.Tick()
  • sending can be done at anytime