中EN

Asserts in Unreal Engine(摘录)

Markdown3 KB 原始文件

Unreal Engine provides three different families of assert equivalents: check, verify, and ensure. If you would like to examine the code behind these features, you can find the relevant macros in Engine/Source/Runtime/Core/Public/Misc/AssertionMacros.h. Each one behaves slightly differently, but they all serve the same general role as diagnostic tools for use during development.

A key feature of assert is that it doesn't exist in shipping code, meaning it has no performance impact on a shipped product, but also must not have any side effects.

Check

The Check family is the closest to the base assert, in that members of this family halt execution when the first parameter evaluates to a false value, and do not run in shipping builds by default.

By default, check macros only operate in Debug and Development builds. "Slow" macros only operate in Debug builds. Setting USE_CHECKS_IN_SHIPPING=1 enables check macros in Test and Shipping builds. [...] Projects should ship with USE_CHECKS_IN_SHIPPING set to its default value of 0.

Macros listed: check/checkSlow, checkf/checkfSlow, checkCode, checkNoEntry, checkNoReentry, checkNoRecursion, unimplemented.

Verify

The Verify family behaves identically to the Check family in most builds. However, Verify macros evaluate their expressions even in builds where Check macros are disabled. This means that you should use Verify macros only when the expression needs to run independently of diagnostic checks.

Verify macros operate fully in Debug, Development, Test, and Shipping Editor builds, except those ending in "Slow", which only operate in Debug builds. Defining USE_CHECKS_IN_SHIPPING to hold a true value, generally 1, overrides this behavior. In all other cases, Verify macros will evaluate their expressions, but will not halt execution or output text to the log.

Ensure

The Ensure family is similar to the Verify family, but works with non-fatal errors. This means that if an Ensure macro's expression evaluates as false, the Engine will inform the crash reporter, but will continue running. In order to avoid flooding the crash reporter, Ensure macros will only report once per Engine or Editor session. If your use case requires that an Ensure macro report every time its expression evaluates as false, use the "Always" version of the macro.

Ensure macros evaluate their expressions in all builds, but only contact the crash reporter in Debug, Development, Test, and Shipping Editor builds.

Macros listed: ensure, ensureMsgf, ensureAlways, ensureAlwaysMsgf.

引用这一章的笔记

输入关键词开始搜索

滚轮或双指缩放 · 拖动平移 · 双击放大 / 还原