# IsValid

> Checks whether the NavWorld has been properly initialized.

## Definition

* **Type:** Method
* **Namespace:** [Unity.AI.Navigation.LowLevel](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel.md)
* **Assembly:** UnityEngine.AIModule

## IsValid()

Checks whether the NavWorld has been properly initialized.

```csharp
public readonly bool IsValid()
```

### Returns

| Type                                                          | Description                                                                                                              |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | `true` if the NavWorld has been properly initialized, or `false` if the underlying navigation system has been destroyed. |

### Remarks

The only way to obtain the single possible valid NavMesh world is through a call to [NavWorld.GetDefaultWorld](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld/getdefaultworld.md). A NavWorld becomes invalid after a call to [NavMesh.RemoveAllNavMeshData](/engine/6000.5/script-reference/unityengine/ai/navmesh/removeallnavmeshdata.md) destroys the underlying navigation data. Use this method before you invoke any other NavWorld operation, to avoid exceptions that Unity throws in the Editor.

### Examples

```csharp
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class IsValidWorldExample : MonoBehaviour
{
    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        if (!world.IsValid())
        {
            Debug.LogWarning("No valid NavMesh world is currently available.");
            return;
        }

        NavLocation location = world.MapLocation(transform.position, Vector3.one, 0);
        if (world.IsValid(location))
            Debug.DrawLine(transform.position, location.position, Color.green);
    }
}
```

## IsValid(NavNode)

Checks whether the node referenced by the specified NavNode is active in the NavMesh.

```csharp
public readonly bool IsValid(NavNode node)
```

### Parameters

**** (\[NavNode]\(/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navnode)): The identifier of the NavMesh node to check.

### Returns

| Type                                                          | Description                                                                                          |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | `true` if the node referenced by the specified NavNode is active in the NavMesh. Otherwise, `false`. |

### Remarks

NavMesh nodes become invalid when Unity removes the NavMesh surface or the links they belong to, or when a modification of the NavMesh in their region replaces them. Calls to [NavMesh.RemoveNavMeshData](/engine/6000.5/script-reference/unityengine/ai/navmesh/removenavmeshdata.md) or [NavMesh.RemoveLink](/engine/6000.5/script-reference/unityengine/ai/navmesh/removelink.md) remove NavMesh surfaces and links. Calls to UpdateNavMeshData, or carving the NavMesh with a [NavMeshObstacle](/engine/6000.5/script-reference/unityengine/ai/navmeshobstacle.md), modify the NavMesh.

### Examples

```csharp
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class IsValidNodeExample : MonoBehaviour
{
    NavNode m_CachedNode;

    void Start()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation location = world.MapLocation(transform.position, Vector3.one, 0);
        m_CachedNode = location.node;
    }

    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        if (!world.IsValid(m_CachedNode))
            Debug.LogWarning("Cached node was removed or replaced; re-map the location.");
    }
}
```

## IsValid(NavLocation)

Checks whether the node referenced by the NavNode contained in the NavLocation is active in the NavMesh.

```csharp
public readonly bool IsValid(NavLocation location)
```

### Parameters

**** (\[NavLocation]\(/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navlocation)): The location on the NavMesh to check. Checking the location is the same as checking `location.node` directly.

### Returns

| Type                                                          | Description                                                                                                             |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | `true` if the node referenced by the NavNode contained in the NavLocation is active in the NavMesh. Otherwise, `false`. |

### Remarks

A [NavLocation](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navlocation.md) returned by [NavWorld.MapLocation](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld/maplocation.md) can become invalid if the NavMesh data changes around its position, for example through carving by a [NavMeshObstacle](/engine/6000.5/script-reference/unityengine/ai/navmeshobstacle.md) or a UpdateNavMeshData call. Verify the location before passing it to other [NavWorld](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld.md) operations.

### Examples

```csharp
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class IsValidLocationExample : MonoBehaviour
{
    public Transform target;

    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation location = world.MapLocation(target.position, Vector3.one, 0);
        if (!world.IsValid(location))
            return;

        Debug.DrawLine(transform.position, location.position, Color.cyan);
    }
}
```
