The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall
The assert statement can be used to add a check for critical prerequisites. It should probably not be used in production code, as a failed assertion will intentionally make the engine crash with a message stating the source file and line number of the failed assertion.
An assertion can be added anywhere in executable code via the following syntax:
The condition must be an expression that evaluates to a bool value. The assertion fails if the condition evaluates to False at runtime. The term
assert(false); will always fail and thus crash, while
assert(true); never fails.
For Unreal Engine 3 it is recommended to use the built-in preprocessor macro
`assert(condition); instead. This macro is only translated to the assert statement when the code is not compiled for final release. (similar to `log)
Failed assertions always cause the game to crash immediately. This might be annoying for game clients, but it could be a serious problem on dedicated servers. Limit the use of assertions to special testing versions of your code, e.g. by using a preprocessor macro. If your code contains assertions, it might be a good idea to document them properly so your testers know about them.
Note that no code after the failed assertion statement will be executed, no matter how deeply nested your function calls are at that point. A failed assertion results in an immediate, but "semi-clean" shutdown. That means the game log file is properly closed, unlike when the game has a "hard" crash or is killed via the task manager. Network connections are not properly shut down though, so the affected client will time out, while clients of an affected server suddenly experience "infinite" lag.
|Declarations||Preprocessor • Classes • Interfaces • Cpptext • Constants • Enums • Structs • Variables (Metadata) • Replication block • Operators • Delegates • Functions • States • Defaultproperties (Subobjects)|
|Types||bool • byte • float • int • name • string • Object • Class • Enums • Structs (Vector ⋅ Rotator ⋅ Quat ⋅ Color) • Static arrays • Dynamic arrays • Delegates • Typecasting|
|Literals||Boolean • Float • Integer • Names • Objects (None ⋅ Self) • Vectors • Rotators • Strings|
|Flow||GoTo • If • Assert • Return • Stop • Switch • While • Do...Until • For • ForEach • Break • Continue|
|Specifiers||Super • Global • Static • Default • Const|
|UnrealScript||Syntax • .UC • .UCI • .UPKG • Comments • #directives • Native|