How to set a timer for the next tick in Unreal Engine

In Unreal Engine, it is possible to set a delay for the function to execute after a single tick, which is sometimes useful when working with UMG/Slate side of things where the widget properties are only available after a complete rebuild, such as obtaining the desired size of the widget’s geometry, which is often not accessible right after initializing or constructing the widget. In such cases, you may want to implement a delay, as described in this article , but sometimes even a single tick delay is sufficient and can enhance the overall user experience, preventing visual hitches and abrupt interactions....

September 15, 2023 · 2 min · Georgy Treshchev

How to save UObject that is represented as an asset in Unreal Engine

You can save any UObject that is represented as an asset within a UPackage using this method: bool SaveToAsset(UObject* ObjectToSave) { UPackage* Package = ObjectToSave->GetPackage(); const FString PackageName = Package->GetName(); const FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension()); FSavePackageArgs SaveArgs; // This is specified just for example { SaveArgs.TopLevelFlags = RF_Public | RF_Standalone; SaveArgs.SaveFlags = SAVE_NoError; } const bool bSucceeded = UPackage::SavePackage(Package, nullptr, *PackageFileName, SaveArgs); if (!bSucceeded) { UE_LOG(LogTemp, Error, TEXT("Package '%s' wasn't saved!...

February 5, 2023 · 1 min · Georgy Treshchev

How to use variant in Unreal Engine

There is a std::variant class template in the standard library that is essentially a type-safe  union. It is generally used when we are not sure in advance which object should be populated from our list of object types, so we assume that one of the specified objects must be there at a time. Unreal Engine has an alternative implementation called TVariant that works the same, except that all the types in the declaring template parameter pack must be unique....

December 30, 2022 · 1 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