🤔

ArgumentNullException#

An ArgumentNullException is thrown when what is passed to a method is null.

Foo bar = null;
// If the method doesn't accept null it may throw an ArgumentNullException.
Method(bar);

The parameter name listed in the error, and the stack trace, are both clues to what is null.

Extension methods#

Be aware that extension methods can throw this exception when the object you invoke the method on is invalid or null.

Crossover with Unity-null#

You can run methods on unity-null objects because they actually still exist. If the method doesn't implement internal checks as expected, this can manifest as an ArgumentNullException instead of a typical NullReferenceException.

AudioSource source = GetComponent<AudioSource>();
// If source was null it will throw an ArgumentNullException.
source.PlayOneShot(clip, 1);

From internal Unity code#

Note that many errors from Unity Editor code can throw an ArgumentNullException, if the stack trace doesn't contain user code then it's likely not your issue, and Unity may just need to be restarted.


After understanding this page's content, visit NullReferenceException to further debug your issue.