Coding conventions for Unreal Engine 4 for C++, Blueprint and Python
Never omit braces with two exceptions:
// early return:
if (condition)
return;
// early continue:
if (condition)
continue;
Always place braces on new lines:
if (condition)
{
statements;
}
else
{
statements;
}
If you’re using multiple inheritance, you should place all super classes after the first one one a new line:
class UFooBarComponent : public UActorComponent,
public IFooInterface,
public IBarInterface
{
// ...
};
Break very long lines (more than 100-200 characters) wherever it makes sense. Indent the following lines of the same statement.
One of the most common cases for are log lines:
UE_CLOG(bShouldLogError, LogFooCategory, Error, TEXT("An error occured while reading the coding conventions! (Source Actor: %s) "
"This can happen if you are reading too fast (current reading speed: %f)"),
*SourceActor->GetName(), SourceActor->ReadingSpeed);
// Optionally align function parameters to aid legibility
MyFunction(FirstParam, SecondParam, true, "some string");
MyFunction(FirstParamVariant, SecondParam, false, "some different string");
UE_CLOG(LogTemp, Log, TEXT("My log message with many parameters %s, %i, %s"),
*StringParameter1, // next lines of statement indented by a single tab
IntParameter, StringParaneter2);
// continue without indent after statement
if (myCondition) // good
if(myCondition) // bad
MyFunction(); // good
MyFunction (); // bad
*
or &
// good
FFoo* MyFoo;
const FFoo* MyFoo;
FFoo* const MyFoo;
FFoo const * const MyFoo;
// bad
FFoo * MyFoo;
FFoo*MyFoo;
FFoo*const MyFoo;
FFoo const*const MyFoo;
return;
break;
// falls through
default
case