🤔

NullReferenceException: UnityEngine.Object — Find#

Expand the function you use and confirm you use it correctly:

GameObject.Find#

Searches for a GameObject by name.

  1. Only active GameObjects can be found.
  2. Names are case-sensitive.
  3. If your path starts with a / then the path must begin at the root of the scene.
  4. Assignment must occur before access. Often you would use Awake to get, and Start to use.

Transform.Find#

Searches for children by name.

  1. Only direct children are returned unless a path is provided.
  2. Names are case-sensitive.
  3. If a path is provided, the path should look like: Child/Descendant/Etc.
  4. Search the scene for all instances of the caller and check all results (t:ExampleComponent for example).
  5. Assignment must occur before access. Often you would use Awake to get, and Start to use.

GameObject.FindWithTag#

  1. Check the console for a UnityException. FindWithTag will throw an exception when used with a tag that does not exist.
  2. Only active GameObjects can be found.
  3. Assignment must occur before access. Often you would use Awake to get, and Start to use.

warning

Double-check the assignment is actually executed. Your code may never called because of an incorrect setup like a misspelt method name.

Find is an expensive method, see alternatives.