https://wiki.beyondunreal.com/w/index.php?action=history&feed=atom Assert statement - Revision history 2017-11-18T03:03:33Z Revision history for this page on the wiki MediaWiki 1.25.1 https://wiki.beyondunreal.com/Assert_statement?diff=40341&oldid=prev Wormbo: created page 2009-12-16T18:29:48Z <p>created page</p> <p><b>New page</b></p><div>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.<br /> <br /> ==Syntax==<br /> An assertion can be added anywhere in executable code via the following syntax:<br /> '''assert('''''condition''''');'''<br /> 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 &lt;code&gt;assert(false);&lt;/code&gt; will always fail and thus crash, while &lt;code&gt;assert(true);&lt;/code&gt; never fails.<br /> <br /> For [[Unreal Engine 3]] it is recommended to use the built-in preprocessor macro &lt;code&gt;`assert(''condition'');&lt;/code&gt; instead. This macro is only translated to the '''assert''' statement when the code is not compiled for final release. (similar to [[`log]])<br /> <br /> ==Usage considerations==<br /> 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.<br /> <br /> 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 &quot;semi-clean&quot; shutdown. That means the game log file is properly closed, unlike when the game has a &quot;hard&quot; 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 &quot;infinite&quot; lag.<br /> <br /> {{navbox unrealscript}}</div> Wormbo