🤔 Unity, huh, how?

🤔

CS0246

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

This error is shown when a type isn't found. This is because either:

What are namespaces?

Namespaces are used to differentiate between different types that share the same name, and are required to be referenced if in use. They are declared in the using block at the top of a script:

using UnityEngine;

Resolution: Adding the appropriate namespace

Adding a namespace with your IDE

Most IDEs will help you reference the appropriate namespaces by providing quick actions when your caret is on the relevant block of code. Visual Studio has Quick Actions, Visual Studio Code has Quick Fixes, and Rider has Intention Actions.

Rider's namespace intention actions

If your IDE isn't showing errors or quick fixes, you need to configure your IDE.

Take care to add the correct namespace.

Adding a namespace manually

To manually resolve this issue, understand what namespace a Type is in by looking at the documentation or source code. The namespace is listed at the top of the documentation.

Documentation

Source code

The Unity C# reference source code. The source code for packages added to a project can be found under the Packages folder in the Project window.

Namespace conflict resolution

If multiple namespaces contain types by the same name, the code needs to specify which is used. You can use this syntax:

using Object = UnityEngine.Object;

I am using the appropriate namespace and still having an issue: