🤔 Unity, huh, how?

🤔

Assignment issues with serialized fields

Common mistakes

1. Mismatched types

You may be using a different type than is being assigned.

  • Using Text when using TextMeshPro objects. Use TextMeshProUGUI or TMP_Text instead.
    Text refers to the legacy UI text1.
  • Using a type under an incorrect namespace. Hover over the type in your IDE and ensure it has the namespace you expect.

2. References between invalid locations

See the valid references diagram to understand what locations can reference each other.
If you're unsure how to reference one location from another, refer to the how-to section.

3. Attempting to assign to default references

If you have a script selected you are not looking at the correct location to assign references.
Select a GameObject or asset (such as a prefab or scriptable object) and assign the reference to an instance.

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.

  1. 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.