Design Patterns Used In Unreal Engine

Design Patterns Used In Unreal Engine

Tags
Unreal Engine
Programming
Published
Author

Command

Delegates can store pointer to functions, TFunctions can store lambda functions, these are also called function object.
 
More about delegates and TFunctions can be read in this article.
 
There are also a lot base classes with a bunch of convenient high-level methods that the derived classes can compose to define their behavior. Examples includes UInputTrigger , UAnimNotify and UGameFeatureAction .
 
In order to use it this way, the base class need to has an EditInlineNew UCLASS specifier.
UCLASS(Abstract, Blueprintable, EditInlineNew, ...) class ENHANCEDINPUT_API UInputTrigger : public UObject { GENERATED_BODY() ... };
 
Also the variable points to the base class need to has an Instanced UPROPERTY specifier.
UPROPERTY(EditAnywhere, Instanced, BlueprintReadWrite, Category = "Input") TArray<class UInputTrigger*> Triggers;
 
Then in blueprint we can specify which subclass we want to use.
notion image

Flyweight

A UAnimMontage and all UAnimNotifys on it are shared by all FAnimMontageInstances.
Another example is Behavior Tree Nodes , they exist as shared objects, meaning that all agents using the same Behavior Tree will share a single set of node instances. For cases where agents need to store and update information related to a node, UE4 provides various methods include set bCreateNodeInstance to true and node memory.

Observer

Prototype

Singleton

State

Double Buffer

Game Loop

Update Method

Bytecode

Subclass Sandbox

Type Object

Component

Event Queue

Service Locator

Data Locality

Dirty Flag

Object Pool

There is no a unified Object Pool in unreal engine, but particles and AGameplayCueNotify_Actor implemented its own pool.

Spatial Partition