x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

My thoughts about Game Design Patterns using Unreal Engine

I have just finished reading the excellent book “Game Programming Patterns”, which you can read for free at http://gameprogrammingpatterns.com/contents.html

The book gives several Unity examples. As a learning exercise I thought I would apply the content of the book to Unreal engine.

Let me start with a very brief summary of the patterns covered by the book:

1.Design patterns revisited

Command Express actions for actors as classes.

Flyweight Separate intrinsic (context-free) and extrinsic (unique to this instance) data to optimize memory.

Observer An object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes.

Prototype Ability to clone objects.

Singleton Singletons harm the code because they are global, making harder to follow the code, encouraging coupling, no concurrent-friendly implementations.

State Finite State Machines

2. Sequencing patterns

Double buffer Cause a series of sequential operations to appear instantaneous or simultaneous.

Game loop Decouple progression of game from user input and processor speed.

Update Method Simulate a collection of independent objects by telling each other to process one frame of behavior at a time.

3. Behavioural patterns

Bytecode Give behavior the flexibility of data by encoding it as instructions for a virtual machine.

Subclass Sandbox Define behavior in a subclass using a set of operations provided by its base class.

Type Object Allow the flexible creation of new “classes” by creating a single class, each instance of which represents a different type of object.

4. Decoupling Patterns

Component Allow a single entity to span multiple domains without coupling the domains to each other.

Event queue Decouple when a message or event is sent from when it is processed.

Service Locator Provide a global point of access to a service without coupling users to the concrete class that implements it.

5. Optimization Patterns

Data Locality Accelerate memory access by arranging data to take advantage of CPU caching.

Dirty flag Avoid unnecessary work by deferring it until the result is needed.

Object Pool Improve performance and memory use by reusing objects from a fixed pool instead of allocating and freeing them individually.

Spatial partitions Efficiently locate objects by storing them in a data structure organized by their positions.


Unreal Design

I have identified the following Unreal tools to implement design patterns: TFunctions, delegates, TSubclassOf, Actor and ActorComponents, Blueprints.

What have I missed?

  • TFunctions can store lambda functions to implement the Command pattern.

  • Udata assets help sharing data by several instances (as the Flyweight pattern indicates)

  • Unreal delegates help organising the code as the Observer pattern suggests. They also decouple code by processing Event queues.

  • TSubclassOf is brilliant. They change programming style to data oriented, as in the Prototype, Type Object Patterns

  • The engine has a game loop as described in https://docs.unrealengine.com/en-US/Gameplay/Framework/GameFlow

  • Every Actor and ActorComponent have a Tick function, following the Update Method pattern.

  • Blueprints are a very fast way to store game logic and iterate gameplay mechanics, as the Bytecode pattern suggests. Also, blueprints can derive from a C++ base class and, making use of UPROPERTIES and UFUNCTIONS, as the Subclass Sandbox pattern.

  • Unreal engine architecture provide Game Instance, Game State or Player State as central places where to add managers (service locators).

  • Finite State Machines are supported by AI blackboards.

Not supported:

  • Singletons cannot be implemented in Unreal. But we know that’s a good thing and we can add managers to the Game Instance class.

  • Optimizing: I want to think Unreal stores contiguous Component arrays (data locality). I’m not sure if there is any support for dirty flag, object pool or spatial partitions?

Thanks for reading, let me know your thoughts!

Product Version: UE 4.20
Tags:
more ▼

asked Oct 28 '18 at 11:10 AM in C++ Programming

avatar image

Capitan Macuto
6 1 1

avatar image Quexlaw Oct 28 '18 at 11:40 AM

Nice read, but I think this is the wrong place to post. The answer hub is strictly for solving problems, not discussion, afaik. You should take this post to the unreal forums instead.

I have read the book too, to some degree, and I overall agree; when I read it, I was thinking about how many of those patterns are effectively used in Unreal. I would not say that AI blackboards are finite state machines though. The blackboards are just data containers. The animation state machine, however, is a state machine (duh).

Also, singletons are "supported". You can write them yourself. The game instance itself is basically a singleton. There may be some difficulties implementing them, but by looking into the source code of a plugin for UE4, I found a singleton class that works.

avatar image Capitan Macuto Oct 28 '18 at 02:31 PM

Thanks Quexlaw, I think you're right. I'll repost my question on the forums.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question