Search Unity

NullReferenceException

Discussion in 'Scripting' started by betike, Jan 16, 2021.

Thread Status:
Not open for further replies.
  1. betike

    betike

    Joined:
    May 28, 2019
    Posts:
    18
    Hello,

    I been getting this error for a while now, but I am able to run my project. Can you please suggest where to look to get rid of this error? Is it somewhere in code or scene?

    Thanks so much!
    The error is below:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.JsonUtility.FromJson[T] (System.String json) (at /Users/bokken/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:30)
    UnityEditor.StateCache`1[T].GetState (System.String key, T defaultValue) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Utils/StateCache.cs:90)
    UnityEditor.Tools.OnEnable () (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/Tools/Tools.cs:422)
    UnityEngine.GUIUtilityProcessEvent(Int32, IntPtr) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)
     
    Last edited: Jan 16, 2021
  2. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    I have never seen this error before and it does not seem related to ML-Agents at all. I think you should ask on more general Unity forums. It seems to be related to Editor UI for what I can see.
     
  3. sjddota065

    sjddota065

    Joined:
    Jan 22, 2021
    Posts:
    2
    You should reset it, it might works for you.
     
  4. osdima1

    osdima1

    Joined:
    Nov 4, 2019
    Posts:
    12
    Same problem here.
     
  5. ervteng_unity

    ervteng_unity

    Unity Technologies

    Joined:
    Dec 6, 2018
    Posts:
    150
    I don't think this is an ML-Agents issue - maybe try re-importing all the assets?
     
  6. danilocjr

    danilocjr

    Joined:
    Oct 4, 2017
    Posts:
    8
    Same. It's been at least for the last 4 months now.
    Probably something with JsonDotNet import?
     
  7. danilocjr

    danilocjr

    Joined:
    Oct 4, 2017
    Posts:
    8
    Hi guys,

    Not using ML and the problem with JSONUtility stays on

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.JsonUtility.FromJson[T] (System.String json) (at /Users/bokken/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:30)
    3. UnityEditor.StateCache`1[T].GetState (UnityEngine.Hash128 key, T defaultValue) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Utils/StateCache.cs:88)
    4. UnityEditor.Tools.OnEnable () (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/Tools/Tools.cs:426)
    Everytime some compilation occurs, this error keep remind me of him :(

    Do you guys have any idea what's happening?? Almost a year with this issue....
     
  8. OtabeTakumi

    OtabeTakumi

    Joined:
    Aug 6, 2020
    Posts:
    1
    Delete the directory below,
    <your-unity-projects-root>/Library/StateCache/
    and reopen Unity.

    This works for me.
     
  9. mrstruijk

    mrstruijk

    Joined:
    Jan 24, 2018
    Posts:
    52
  10. hjo4411

    hjo4411

    Joined:
    Aug 12, 2021
    Posts:
    1
    awesome this works with me
     
  11. dexmex001

    dexmex001

    Joined:
    Oct 9, 2019
    Posts:
    24
    Thanks a lot, its worked me
     
  12. redknight158

    redknight158

    Joined:
    Jul 20, 2017
    Posts:
    18
    This works for me but only temporarily. After a few plays, it comes back... any suggestions?
     
  13. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    Find what is making it null again. And PLEASE don't necro-post for trivial nullref problems.

    How to fix a NullReferenceException error

    https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

    Steps to success:
    - Identify what is null
    - Identify why it is null
    - Fix that

    You must find a way to get the information you need in order to reason about what the problem is.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494
     
  14. wiki1135

    wiki1135

    Joined:
    May 22, 2013
    Posts:
    2
    thank you !
     
Thread Status:
Not open for further replies.