[S-Unreal-011] C++ Standardization
Upload In Progressthis article:
Overview
This section will focus on Blueprint classes and their internals. When possible, style rules conform to Epic's Coding Standard.
It’s already difficult working in C++, and now we need to deals with C++ in Unreal style with their own module linker system that have huge amount of module where you see macros everywhere. Not to mention the C++ code we write would be the baseline for blueprint that have another convention and standard. If we don’t manage it right, chaos will knock at our door and become our guest.
Scope
This standardization cover the Unreal Style Guideline about how to work in Unreal. This standard applies to all person in in team that work using Unreal Engine.
Technical Director and Art Director was the parties whose in charge in these guidelines. While all of the team member should follow these guidelines, they can ask about the guidelines to the directors or can propose some new guidelines here and there.
C++ Standardization
[S-Unreal-011.1] Compiling
Due to unreal that treat Warning as Error, we need to fix all the Warning. Never ignore or disable warning because sometimes it will make issues when we build the game using another version of engine such as custom build engine.
[S-Unreal-011.1.1] Headers and C++ Files
- Include headers in a specific order: Unreal Engine headers, followed by standard library headers, and then project-specific headers. Optionally it can be separated with 1 empty line between each group.
- Use forward declarations when possible and actually include the header in C++ class whenever possible to minimize header dependencies and reduce compile time.
[S-Unreal-011.2] Variables
Other than what mentioned here, all of the rules should follow Variables rules in Blueprint Standardization.
[S-Unreal-011.3] Functions and Delegates
Other than what mentioned here, all of the rules should follow Functions, Events, and Event Dispatchers rules in Blueprint Standardization, where Delegates equal Event and Event Dispatcher.
- Exposed function to blueprint should have comments for documenting code.
- Avoid long functions; aim for single responsibility functions.
[S-Unreal-011.4] Preprocessors Directive
- Avoid using
#define
for constants. Instead, useconst
orenum
where possible. - Preprocessor macros should be in all uppercase, e.g.,
MY_MACRO
.
[S-Unreal-011.5] Comments Classes, Functions, and Variables Usage
This will help a lot of team member that work in blueprint using the function.
Here are some key point to make it readable in blueprint tooltips.
-
Use triple slash
- Use
/// ...
-
Do not use
/** ... */
- Use
-
Parameter
- Use
@param
followed byParamNames
then the parameter description
- Use
-
Return
- Use
@return
followed by return description - ,
@brief
, and more, which provide information about parameters, return values, and the purpose of functions and classes.
- Use
[S-Unreal-011.6] Formatting
- Use tab instead of four-space indents for code.
- Place opening curly braces on different line as the statement (e.g.,
if
statements).
[S-Unreal-011.7] Casting
- Prefer using Unreal Engine casting functions like
Cast<>
orStaticCast
for safe type conversion.
[S-Unreal-011.8] Namespace
- Avoid using
using namespace
in header files. Instead, use the full namespace to avoid naming conflicts.
Reference
- https://github.com/Allar/ue5-style-guide
- https://www.unrealdirective.com/resource/asset-naming-conventions
- https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/AssetNaming/
Related Pages
[S-Unreal] Unreal Style Guidelines
[G-Production-001] Development Principles
[S-Unreal-001] Unreal Standardization Terminology
[S-Production-001] General Naming Convention
[S-Unreal-002] Unreal Asset Naming Convention
[S-Unreal-003] Unreal Folder Structure & Naming Convention
[S-Unreal-004] Textures Standardization
[S-Unreal-005] Static Meshes Standardization
[S-Unreal-006] Skeletal Meshes Standardization
[S-Unreal-007] Media Standardization
[S-Unreal-008] Niagara Particle System Standardization
[S-Unreal-009] Maps Standardization