Panic in UnrealScript
Our example demonstrates how to handle unexpected errors or critical situations in UnrealScript. In UnrealScript, we don’t have a direct equivalent to panic
, but we can use assert
for similar purposes.
Running this code will cause an assertion failure, print an error message, and potentially crash the game or editor, depending on how assertions are configured in the project.
When the first assertion in CheckCondition
fails, the function execution will stop, and the rest of the code won’t be reached. If you’d like to see the function try to create a new object, comment out the first assertion.
In UnrealScript, assertion failures typically result in error messages in the log or on-screen, and may halt execution depending on project settings. The exact output format can vary, but it might look something like this:
Note that unlike some languages which use exceptions for handling many errors, in UnrealScript it’s common to use return values, boolean flags, or specific error-handling functions to manage and respond to error conditions. Assertions are typically used for detecting programmer errors or impossible situations, rather than for regular error handling.
In UnrealScript, you might also use the log
function for non-critical error reporting:
This allows for error reporting without necessarily halting execution, which can be useful during development and debugging.