🤔

CS0246: Assembly Definitions#

The type or namespace name 'Foo' could not be found (are you missing a using directive or an assembly reference?)

Assembly Definitions (asmdefs) are used to manually group code into individual assemblies. They also define the references between those assemblies, giving you tighter control over your compilation.

Learn more about Assembly Definitions.

Resolution#

Navigate to the heading that fits your setup and complete the listed steps.

Both scripts are under separate Assembly Definitions#

  1. Select the asmdef that contains the current script.
  2. In the Assembly Definition References section of the inspector add a reference to the asmdef that contains the script you wish to reference.
  3. Make sure you're not trying to reference an Editor-only assembly (see image) from a runtime one.
  4. Apply and wait for Unity to recompile. The reference should now be resolved when the namespace is added.

Editor Assembly Definition

Editor-only Assembly Definition

This script is under an Assembly Definition, the target is in a plugin/DLL#

  1. Select the asmdef that contains the current script.
  2. Under General, tick Override References.
  3. In the Assembly References section of the inspector add a reference to the target plugin.
  4. Apply and wait for Unity to recompile. The reference should now be resolved when the namespace is added.

This script is under an Assembly Definition, the target isn't#

If the target is Unity's assemblies No Engine References must not be ticked on the asmdef.

If the target is in your project but not in an asmdef it cannot be referenced by code in an Assembly Definition. You may want to consider adding asmdefs to all parts of your project where possible. Adding them to external plugins for compatibility with your project is a normal thing to do.

This script isn't under an Assembly Definition, the target is#

Scripts outside of asmdefs can reference asmdef assemblies if Auto Referenced is ticked on their asset. If it isn't and can't be changed, then this code must be moved under its own asmdef to have it reference that assembly.

Neither scripts are under Assembly Definitions#

You can search the project with t:AssemblyDefinitionAsset to find asmdefs in the project, making sure none are above your scripts.

Continue debugging with Editor assemblies.


I am still having issues referencing a type.