Daily Unreal Column #42 - Assertions
Unreal Engine has three main groups of assertions: checks, ensures and verifiers. Here are the differences between them.
My personal favorite among the three mentioned assertions is an ensure
. Reason for that is, when the expression inside it evaluates to false, it notifies the crash reporter about it and triggers a debug break, however, it doesn't kill the process and allows to continue for the program to run. This is great to catch certain issues without actually crashing the editor which can cost a lot of time. Here is a very common pattern I am using when writing code:
if (!ensure(SomeExpressionIExpectToBeTrue))
{
return;
}
Instead failing silently, we do this and we get a debug break when/if it fails.
check
on the other hand will kill the process and there is no way to recover. What's super important about `check` is to remember that its expressions are not being evaluated in shipping builds. This is where verify
comes into play. It is doing exact same thing check
is doing, except in shipping builds it still evaluates the expression but doesn't check the result.
For more details and example usages read this doc page which is actually doing very decent job in explaining all variations of these assertions.