Unity AI Toolkit Scripts Not Found After Import - Package Installation Fix

You import the Unity AI Toolkit (or a related AI package) and scripts are not found. Errors like "The type or namespace name could not be found" or "Assembly 'Unity.AI...' has not been found" appear, and your project will not compile. This guide walks you through fixing missing AI Toolkit scripts and package installation issues.

The Problem

After adding or updating the Unity AI Toolkit (or ML-Agents, AI Navigation, or other AI packages), you see:

  • CS0246: The type or namespace name 'X' could not be found
  • Assembly 'Unity.AI.Navigation' (or similar) has not been found
  • Scripts missing or greyed out in the Project window
  • Package appears in Package Manager but scripts do not compile
  • Red errors in Console related to AI or ML-Agents namespaces

These indicate that the package is not fully installed, not referenced by your assemblies, or that the wrong package version is in use.

Why This Happens

Package not fully installed

  • Import or install was interrupted or failed partway.
  • Package Manager shows the package but files are missing or corrupted.
  • A dependency of the AI package failed to install.

Assembly definition (asmdef) not referencing the package

  • Your scripts live in an Assembly Definition that does not reference the AI package assemblies.
  • Unity only compiles scripts that can see the AI assemblies; if your asmdef does not list them, you get "type or namespace could not be found."

Wrong or incompatible version

  • Unity version does not match the package’s required version.
  • Package was updated and APIs or assembly names changed.
  • Multiple AI-related packages conflict.

Scoped registry or package source issues

  • Package comes from a scoped registry that is not added or is misconfigured.
  • Network or permissions prevent the package from downloading completely.

Solution 1: Reinstall the Package via Package Manager

Often the package did not install completely. Reinstalling fixes missing scripts.

Step 1: Remove the package

  1. Open Window > Package Manager.
  2. Select Unity Registry (or the registry that provides the AI package).
  3. Find the AI package (e.g. AI Navigation, ML-Agents, Unity AI Toolkit).
  4. Click Remove and confirm.
  5. Wait for Unity to reimport and compile.

Step 2: Install the package again

  1. In Package Manager, select the same registry.
  2. Find the AI package and click Install (or Add).
  3. Wait until the status shows Installed and the progress bar finishes.
  4. Check the Console for any errors during install.

Step 3: Verify scripts are present

  1. In the Project window, search for a known script from the package (e.g. NavMeshAgent, or a class name from the package docs).
  2. Confirm the script file exists under Packages/<PackageName>/.
  3. If it is there but you still get "type or namespace could not be found," go to Solution 2.

Verification: After reinstalling, close and reopen Unity if needed, then trigger a recompile (e.g. switch to another script and back). Errors related to that package should clear if the install is complete.

Solution 2: Add the Package Assembly to Your Assembly Definition

If your scripts are in an Assembly Definition (.asmdef) file, that asmdef must reference the AI package assembly. Otherwise Unity will not let your code see the AI types.

Step 1: Find your script’s assembly

  1. Select the script that shows "type or namespace could not be found" in the Project window.
  2. In the Inspector, check Assembly Definition (or look at the folder: if it is under a folder with an .asmdef, it belongs to that assembly).

Step 2: Edit the Assembly Definition

  1. Select the .asmdef file that contains your script (same folder or parent folder).
  2. In the Inspector, find Assembly References.
  3. Click + and add the AI package assembly (e.g. Unity.AI.Navigation, Unity.ML-Agents, or the name shown in Package Manager for that package).
  4. Save (Ctrl+S) and wait for Unity to recompile.

Step 3: Confirm assembly name

  • In Package Manager, select the AI package and check the Assembly definitions or Documentation for the exact assembly name (e.g. Unity.AI.Navigation).
  • The name in your asmdef references must match exactly.

Verification: After adding the reference, the Console should recompile without the "could not be found" errors for that namespace. If errors remain, double-check the assembly name and that the package is really installed (Solution 1).

Solution 3: Use the Correct Package and Version

Different Unity versions and features use different packages. Using the wrong one can lead to "scripts not found" or missing APIs.

Step 1: Confirm which AI package you need

  • AI Navigation (NavMesh, agents) – Usually AI Navigation or Unity AI Navigation.
  • ML-Agents (reinforcement learning) – ML-Agents or Unity ML-Agents.
  • Other AI Toolkit features – Check Unity’s AI or package documentation for the exact package name and version.

Step 2: Check Unity and package compatibility

  1. In Package Manager, select the package and read the Version and Verified / Recommended note.
  2. In Help > About Unity, confirm your Unity version.
  3. Install a version of the package that is verified or recommended for your Unity version.
  4. If you are on a very new Unity version, try the latest package; if that fails, try the previous minor version.

Step 3: Resolve conflicts

  • If you have more than one AI-related package (e.g. old ML-Agents and new AI Toolkit), remove the one you are not using to avoid duplicate or conflicting assemblies.
  • After changing packages, run Assets > Reimport All only if necessary; usually closing and reopening the project or recompiling is enough.

Verification: Package Manager shows the package as Installed with no warnings, and your project compiles. If the package’s samples or demo scenes are available, open one to confirm the package works in your editor version.

Solution 4: Clear Caches and Reimport (If Scripts Still Missing)

If the package is installed and referenced but scripts still do not appear or compile:

  1. Close Unity.
  2. Delete the project’s Library folder (Unity will regenerate it). Optional but often fixes stuck imports.
  3. Reopen the project and wait for Unity to reimport.
  4. In Package Manager, Remove the AI package, then Install it again.
  5. If your scripts use an asmdef, re-add the package assembly reference (Solution 2).

Verification: After reopening and reimport, search again for the package’s scripts in the Project window and confirm Console has no missing-type errors.

Alternative Fixes and Edge Cases

  • Scoped registry: If the AI package comes from a scoped registry (e.g. Unity’s preview registry), add it under Edit > Project Settings > Package Manager > Scoped Registries and ensure the registry URL and scope are correct. Then install from that registry in Package Manager.
  • Git or external package: If you added the package via Git URL or local path, ensure the path is correct and that the package’s package.json and assembly definitions are present. Re-clone or re-add if files are missing.
  • Scripting backend: Some packages require a specific scripting backend (Mono vs IL2CPP). Check the package docs; usually this does not cause "scripts not found" but can cause runtime errors later.

Prevention Tips

  • After adding an AI package, wait for Package Manager to finish and for the first compile to complete before writing code that uses it.
  • If you use asmdefs, add the new package’s assembly reference as soon as you install the package.
  • Stick to verified or recommended package versions for your Unity version.
  • Keep a backup or use version control before removing and reinstalling packages, in case you need to revert.

Related Problems and Links

For official package and version requirements, see the Unity AI Navigation or ML-Agents documentation for your Unity version.

Bookmark this fix for quick reference. If this solved your issue, share it with other developers who hit the same error.