Georgy Treshchev

Unreal Engine C++ developer.

  • I like creating various engine tools that simplify the development process.
  • Feel free to email me at [email protected] or join telegram chat for any questions.

How to properly work with UObjects in background threads

This short article addresses the question of how to work with UObjects in a thread-safe way when passing them to some workers, asynchronous tasks, thread pools, or whatever else using a non-game thread. One of the most important issues here is garbage collection. When we pass a UObject* that is not set to root directly to a background thread, it is possible that the passed UObject may be silently deleted by the garbage collector....

November 30, 2022 · 2 min · Georgy Treshchev

How to pass a variable by reference in C++ function called in Blueprints

By default, when a non-const reference is specified in a function, it will be treated by Blueprints as an output parameter: Show/hide content UFUNCTION(BlueprintCallable) static void RemoveDots(FString& String) { String.ReplaceInline(TEXT("."), TEXT(" ")); } There is a macro called UPARAM which is not widely used, but can control the behavior of parameters specified in UFUNCTIONs. In particular, it can change the behavior of passing non-const references by specifying a ref meta:...

August 14, 2022 · 1 min · Georgy Treshchev

How to async task in Unreal Engine

Unreal Engine has a nice feature called AsyncTask, which is used to execute a code asynchronously. It works by running certain code on a specified thread, and this functionality is mostly used when the task is heavy enough to be executed instantly without blocking the game thread. It also provides a solution to all issues arising from multithreading, in particular, accessing parameters from one thread that are supposed to be used and/or edited in another thread....

July 31, 2022 · 2 min · Georgy Treshchev

How to create a multi-threaded for loop in Unreal Engine

Unreal Engine has different approaches to parallelize your code and one of them is ParallelFor. It is used when it is necessary to execute code multiple times with different number-based inputs, basically what a regular for loop does. But unlike a regular for loop that executes sequentially, ParallelFor runs on different threads, with possible different order of execution. Let’s say our task is to simply sum the values from the TArray<int32> array....

July 23, 2022 · 2 min · Georgy Treshchev

How to use delays in C++ in Unreal Engine

Some developers are wondering about the C++ equivalent of the Delay node in Blueprints. In C++, it is not recommended to make delays for cosmetic things. But if there are something that require high optimization, then consider the following ways. There are two ways to implement Delay that are very similar. Use the option that is more readable and convenient for you. Lambas Using FTimerDelegate FTimerDelegate TimerDelegate; TimerDelegate.BindLambda([&] { UE_LOG(LogTemp, Warning, TEXT("This text will appear in the console 3 seconds after execution")) }); FTimerHandle TimerHandle; GetWorld()->GetTimerManager()....

July 3, 2022 · 1 min · Georgy Treshchev