Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Trace ArgumentException

Discussion in 'Scripting' started by elder0010, Mar 19, 2021.

  1. elder0010

    elder0010

    Joined:
    Oct 31, 2015
    Posts:
    14
    Hello, I have an ArgumentException

    Code (CSharp):
    1. ArgumentException: The Object you want to instantiate is null.
    which is presumably thrown by an Instantiate() call.

    Clicking on the error in console the GameObject containing the script that throws the error is highlighted in hierarchy, but i cannot find a way to see which script / line is causing the error.
    Is there a way to "trace" it?
    I am using Unity 2020.2.4f1

    thanks
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    It's kind of annoying: some things you can doubleclick on and it takes you there, some (like this and others) you cannot.

    instead, single-click on it, then look in the lower portion of the console to see the callstack how you got theere.
     
    mangosauce_ likes this.
  3. mangosauce_

    mangosauce_

    Joined:
    Jan 26, 2020
    Posts:
    13
    Well, if you know which gameObject is causing the error, it might be simplest just to look through each of the Instantiate() calls in that object's scripts. Otherwise, using Debug.Log messages before each instantiation call, or using try-catch blocks to throw custom errors, might help you pinpoint exactly where things go awry.
     
  4. elder0010

    elder0010

    Joined:
    Oct 31, 2015
    Posts:
    14
    Fixed: right click on the console tab, go to Stack Trace Logging > Error > ScriptOnly
    thanks guys!
     
    mangosauce_ and Kurt-Dekker like this.