Community Tutorial: Rama Code: Multi-Threading in UE5 C++

Dear Community,

Here is my UE5 C++ Multi-threading tutorial!

I hope you enjoy the video!

I give you the >>> entire UE5 project <<< that you see in the video, as well as the C++ code, in the link below!

https://dev.epicgames.com/community/learning/tutorials/7Rz/unreal-engine-rama-code-multi-threading-in-ue5-c

1 Like

In the guide the example you give is a Throttled Thread.
If I wanted the length of the tick in my thread to match the length of the tick in the GameThread what changes would I make to do so? Is there an easy change I could make to achieve this?

Thanks :slight_smile:

1 Like

Right here!

You could update the thread dynamically to match game thread, but if you are doing something where thread-synchronization is that sensitive you should probably reconsider your design architecture!

A very fast tick rate is 0.001, SUPER fast is 0.0001.

Keep in mind that 200 FPS

is 1/200 = 0.005 seconds

void ARamaCodeMultiThreadActor::JoyThread_Init()
{
      //...

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// 					 Thread Tick Rate
	//!!! MAKING THIS ENTIRE PROCESS GO SLOWLY OR QUICKLY
	//!!! ATTENTION: COMPUTER RESOURCE MANAGEMENT DEPT OF YOUR GAME LOGICS
	//!!! <3 RAMA
	FTimespan ThreadWaitTime = FTimespan::FromSeconds(0.01);  //! Use 0.1 or higher if don't need calcs to occur quickly!

:heart: Rama

Hi Rama! First, thank you a lot for everything you’ve done to the community. There are lots of people like me that grew on your tutorials!

Secondly, in my testing, this variable that you are changing doesn’t have an effect on the tick rate. I tested it like so:

  1. Donwloaded your repository
  2. Changed FTimespan ThreadWaitTime 10 times lower and 10 times higher. It didn’t make any difference.
  3. Moreover judging by the code, your ThrottledThreadTime is only being used in one section of the code: FRamaCodePrimeCalcThread::JoyTick(), however this thing is never called during the generation of prime numbers, hence it doesn’t have any effect on the logic rather than initial delay.
1 Like

Hi there @fateful_student !

:heart: You’re welcome! :heart:

Yes, you are right!

I had changed my code to make sure a hitch would be visible and obvious if the threading did not get set up correctly.

In a realistic case, you would want to not do the entire loop in a single tick, also so that the thread uses less resources, while taking a little bit longer to complete.

Then the thread throttling will also take effect, if you do only a few of your calculations per tick.

Sorry, a little bit of tweaking required for a realistic case.

My video demonstrates a Gigantic calculation occurring in 1 single chunk, on another operating system level thread, to prove the multi threading is truly solid, and working

Lovely to hear from you!

:heart:

Rama

1 Like