Debug.Log Extensions
Documentation (1.1.9)

◆ Ensure() [5/5]

static bool Debug.Ensure ( bool  condition,
int  channel,
string  message,
Object  context = null 
)
static

If condition is false logs to the Console on the given channel an error message and returns false.

If condition is true returns true without logging anything.

An error is only logged the first time during a session that the condition evaluates to false to avoid flooding the log file.

This can be useful for checking that the arguments passed to a function are valid and only executing a block of code if so.

In release builds an error will only be logged if the UNITY_ASSERTIONS symbol is defined.

private float Divide(float dividend, float divisor)
{
return Debug.Ensure(divisor != 0f) ? dividend / divisor : 0f;
}
static bool Ensure(bool condition, Object context=null)
If condition is false logs to the Console an error message and returns false.
Definition: Debug.cs:3838
Extended version of the built-in Debug class with additional methods to ease debugging while developi...
Definition: Debug.cs:34
Returns
true if condition was true; otherwise, false.
Parameters
conditionCondition you expect to be true.
channelThe channel to which the message belongs if logged.
messageMessage to display if condition is false.
contextObject to which the assertion applies.