Coding conventions for Unreal Engine 4 for C++, Blueprint and Python

Project Setup
Assets
Blueprint
C++
Python

View the Project on GitHub JonasReich/OpenUnrealConventions

Open Unreal Conventions

The Open Unreal Conventions are an open source set of coding and asset conventions for Unreal Engine 4 projects created and maintained by Jonas Reich.

These conventions should serve as a foundation for all aspects of Unreal Engine development. This means they cover not only C++ code, but also Blueprints, Python and Asset creation. Over time we might also add some conventions for complementary tools like batch scripts for building Unreal Engine games.

Subpages

Project Setup

Asset Conventions

Blueprint Conventions

C++ Coding Conventions

Python Coding Conventions

WIP Status

The coding conventions are a work-in-progress project. This list shows the current status of the sub-conventions:

domain progress
Project Setup 50%
Assets 90%
Blueprint 50%
C++ 90%
Python 100%

General Structural Rules

Structure Content with the Uninformed Developer in Mind

You probably are not the only developer in a project. And even if you are you will most certainly come back to a piece of code, a blueprint or an asset folder that you haven’t seen in a while. It is very likely that you will forget and re-learn half of the things you worked on over the course of a project.

Creating a structure that is easily parse-able for an uninformed viewer is crucial for project maintainability. And all other rules are based on this very thought.

This should usually manifest in thinking about the big picture first and structuring your content from big to small.

The Magical Number Seven (Plus or Minus Two)

There is a rule in psychology stating humans cannot easily separate and memorize groups of more than seven objects (plus minus seven). We can apply this rule to our C++ code and Blueprints saying you should introduce logical groupings once you have more than 7-10 variables, functions, etc.

Of course this all depends on the context, but it’s a good rule of thumb to recognize code, blueprints, etc that are too crowded.

General Programming Rules

For all logical programming no matter the language (Blueprints, C++, Python) you must always adhere to the following basic rules:

  1. Leave a file at least as clean as you found it
  2. Fix errors when you stumble across them
  3. Don’t submit any broken code including code that you know throws errors or warnings
  4. Your code must always be clean, well formatted and properly documented
  5. You must always stick to SOLID principles and write DRY code
  6. Consistency is king. Stick to existing conventions and establish new ones as soon as you do something not covered by conventions.
  7. Never leave any dead/unreachable/commented-out code

General Naming Rules

Always use PascalCase. This applies for assets, folder names, variable names, function names, you name it.

Never use spaces for names. This is mainly important for asset and folder names (including the folders in which you store your unreal projet), but can also be extended to variables and functions in your Blueprints.

Stick to Latin Alphanumerics and underscores. Never use special unicode characters, umlauts or any other special characters. In short, stick to this set of characters:

ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789_

Keep names short and concise. Short and readable is the key here. Other devs still need to understand what you mean. Unreal enforces a 180 character path limit for all source files and assets, so keeping file and folder names short is essential. It also makes file lists, debug logs, etc easier to read. This last point also applies to function and variable names.

References

These coding conventions are based on a mixture of the following coding conventions:

Further Reading

The following sources are reccommended reading material for their respective topic:

License

The Open Unreal Conventions are licensed under the MIT license.

Contributing

You are invited to create pull-requests to the github source for any additions or modifications you make to the guidelines.