Thread safe manipulation of game play objects/actors

Actually There Must Be a Way

On second thought there must be a way to safely send message to Blueprints, because I am doing it via a UDP Socket thread in this wiki tutorial:

If you use a delegate that is sending threadsafe data you should be fine

//UdpSocketReceiver.h



/**
 * Asynchronously receives data from an UDP socket.
 */
class FUdpSocketReceiver
	: public FRunnable




/**
 * Temporary fix for concurrency crashes. This whole class will be redesigned.
 */
typedef TSharedPtr<FArrayReader, **ESPMode::ThreadSafe**> FArrayReaderPtr;

/**
 * Delegate type for received data.
 *
 * The first parameter is the received data.
 * The second parameter is sender's IP endpoint.
 */
DECLARE_DELEGATE_TwoParams(FOnSocketDataReceived, const FArrayReaderPtr&, const FIPv4Endpoint&);


I will go do some testing. :slight_smile:

Okay my testing results:

If I use a wait time with thread safe data before sending to BP, it works great.

But if I just let the thread go full throttle than it crashes Blueprints pretty quick.

Have you tried simply adding a wait time to your thread?

Even a wait time of 0.01 is not crashing.

0.001 or 0.0001 does crash though :slight_smile:

That will still have advantages over using game thread, even if the other thread is not running at infinite speeds.

You can try sleeping for various numbers of seconds, putting this inside your Run() (ensuring it will slow down whenever you are sending a message to BP)



FPlatformProcess::Sleep(seconds);


:heart:

1 Like