# Assert

> Assert a condition and logs an error message to the Unity console on failure.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## Assert(bool)

Assert a condition and logs an error message to the Unity console on failure.

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) on the MSDN website.

## Assert(bool, Object)

Assert a condition and logs an error message to the Unity console on failure.

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition, Object context)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.**** (\[Object]\(/engine/6000.7/script-reference/unityengine/object)): Object to which the message applies.

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) on the MSDN website.

## Assert(bool, Object)

Assert a condition and logs an error message to the Unity console on failure.

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition, object message)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.**** (\[Object]\(https\://learn.microsoft.com/dotnet/api/system.object)): String or object to be converted to string representation for display.

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) on the MSDN website.

## Assert(bool, string)

Assert a condition and logs an error message to the Unity console on failure.

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition, string message)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String or object to be converted to string representation for display.

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) on the MSDN website.

## Assert(bool, Object, Object)

Assert a condition and logs an error message to the Unity console on failure.

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition, object message, Object context)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.**** (\[Object]\(https\://learn.microsoft.com/dotnet/api/system.object)): String or object to be converted to string representation for display.**** (\[Object]\(/engine/6000.7/script-reference/unityengine/object)): Object to which the message applies.

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) on the MSDN website.

## Assert(bool, string, Object)

Assert a condition and logs an error message to the Unity console on failure.

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition, string message, Object context)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String or object to be converted to string representation for display.**** (\[Object]\(/engine/6000.7/script-reference/unityengine/object)): Object to which the message applies.

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) 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\[])
>
> **Upgrade to** [Debug.AssertFormat](/engine/6000.7/script-reference/unityengine/debug/assertformat.md)

```csharp
[Conditional("UNITY_ASSERTIONS")]
public static void Assert(bool condition, string format, params object[] args)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Condition you expect to be true.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): **** (\[Object\[]]\(https\://learn.microsoft.com/dotnet/api/system.object)):&#x20;

### Remarks

Message of a type of [LogType.Assert](/engine/6000.7/script-reference/unityengine/logtype/assert.md) 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](https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute\(v=vs.110\).aspx) on the MSDN website.
