Modular Features (IModularFeatures) in Unreal Engine

Do not confuse Modular Features with Modular Gameplay Features . Introduction In Unreal Engine, Modular Features is a pretty straightforward system that makes it possible create and manage features that can be enabled or disabled at runtime. Features share the same base interface (derived from IModularFeatures), and they can be registered/unregistered at runtime from any part of the code and any module. This system is widely used in UE, for example, in audio capture, where each platform may have its audio capture implementation registered/unregistered based on the target platform, all using the base interface of IAudioCaptureFactory, which is derived from IModularFeatures....

April 7, 2024 · 3 min · Georgy Treshchev

Efficient HTTP file download by chunks in Unreal Engine C++

Chunk downloading is a technique used to retrieve large binary data from the server in separate parts, ensuring reliability and compatibility across different platforms. Unreal Engine’s HTTP module has a limitation of 2GB for binary HTTP response content due to internal restrictions (specifically, TArray<uint8> uses the int32 size type, which has a maximum value of 2,147,483,647, approximately 2 GB in our case). To overcome this limitation, we can use the Range HTTP header supported by most servers, without requiring any file preparation or segmentation....

May 21, 2023 · 4 min · Georgy Treshchev

How to use mutex in Unreal Engine

Unreal Engine has an alternative implementation of std::mutex called FCriticalSection which makes it possible for your data to be safely accessed from different threads, preventing race conditions. This takes the same approach, handling it with one thread locking until the other thread completes the necessary operations. There are two ways to handle lock/unlock logic. The first is low-level, which is used to directly lock and unlock threads. Use with caution due to possible deadlocks ....

December 21, 2022 · 2 min · Georgy Treshchev

How to properly work with UObjects in background threads (GC)

This article addresses the question of how to work with UObjects in a thread-safe way when dealing with workers, async tasks, thread pools, or whatever else using a non-game thread. One critical issue to address is the handling of garbage collection. When passing an UObject, which is not set to root, directly to a background thread, there’s a risk that the garbage collector may silently delete the passed UObject. Even frequent validity checks of the UObject (e....

November 30, 2022 · 4 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