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 use async task in Unreal Engine

Unreal Engine has a useful feature called AsyncTask that allows you to execute code asynchronously. It functions by running specific code on a specified thread and is primarily used when the task is too heavy to be executed instantly without blocking the game thread. It also provides a solution to issues arising from multithreading, particularly accessing properties from one thread that are intended to be used and/or modified 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. 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().SetTimer(TimerHandle, TimerDelegate, 3, false); Using FTimerHandle only FTimerHandle TimerHandle; GetWorld()->GetTimerManager().SetTimer(TimerHandle, [&]() { UE_LOG(LogTemp, Warning, TEXT("This text will appear in the console 3 seconds after execution")) }, 3, false); Separate functions The second way is to use a delay to execute another function....

July 3, 2022 · 1 min · Georgy Treshchev

How to completely disable Tonemapper in Unreal Engine

In this quick tutorial, I will show you how to completely disable Tonemapper without using PostProcess To do this, just open the DefaultEngine.ini file (in the [PROJECT_NAME]/Config folder) and add the following lines to [/Script/Engine.RendererSettings] section: r.TonemapperGamma = 0 r.TonemapperFilm = 0 r.Tonemapper.Quality = 0 r.ToneCurveAmount = 0 r.Mobile.TonemapperFilm = 0 r.MobileTonemapperUpscale = 0 r.EyeAdaptationQuality = 0 r.EyeAdaptation.ExponentialTransitionDistance = 0 You can also write the same to the engine’s command line, but I recommend to directly add these lines to a file since it’s more convenient and will always work....

June 26, 2022 · 1 min · Georgy Treshchev