Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Assert

Assert a condition and logs an error message to the Unity console on failure.
Read time 4 minutesLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

Assert(bool)

Assert a condition and logs an error message to the Unity console on failure.
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition)

Parameters

condition

Condition you expect to be true.

Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.

Assert(bool, Object)

Assert a condition and logs an error message to the Unity console on failure.
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition, Object context)

Parameters

condition

Condition you expect to be true.

context

Object to which the message applies.

Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.

Assert(bool, Object)

Assert a condition and logs an error message to the Unity console on failure.
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition, object message)

Parameters

condition

Condition you expect to be true.

message

String or object to be converted to string representation for display.

Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.

Assert(bool, string)

Assert a condition and logs an error message to the Unity console on failure.
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition, string message)

Parameters

condition

Condition you expect to be true.

message

String or object to be converted to string representation for display.

Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.

Assert(bool, Object, Object)

Assert a condition and logs an error message to the Unity console on failure.
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition, object message, Object context)

Parameters

condition

Condition you expect to be true.

message

String or object to be converted to string representation for display.

context

Object to which the message applies.

Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.

Assert(bool, string, Object)

Assert a condition and logs an error message to the Unity console on failure.
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition, string message, Object context)

Parameters

condition

Condition you expect to be true.

message

String or object to be converted to string representation for display.

context

Object to which the message applies.

Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.

Assert(bool, string, Object[])

Assert a condition and logs an error message to the Unity console on failure.
Warning
Removed. Assert(bool, string, params object[]) is obsolete. Use AssertFormat(bool, string, params object[])
[Conditional("UNITY_ASSERTIONS")]public static void Assert(bool condition, string format, params object[] args)

Parameters

condition

Condition you expect to be true.

format


Remarks

Message of a type of LogType.Assert is logged.
Note that these methods work only if UNITY_ASSERTIONS symbol is defined. This means that if you are building assemblies externally, you need to define this symbol otherwise the call becomes a no-op. (For more details see System.Diagnostics.ConditionalAttribute on the MSDN website.