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

Question Empty Scene => NullReferenceException on play without Stacktrace => ???

Discussion in 'Scripting' started by Axel-F, Feb 22, 2023.

  1. Axel-F

    Axel-F

    Joined:
    Mar 20, 2009
    Posts:
    223
    Well, this is really curious.

    In my project - in every scene - and even in an empty scene (!!) - I'm getting a NullReferenceException when starting the scene. But without any context or stacktrace:



    How to figure out whats happening here? I checked the Unity Editor Log and all what can be found there is a line with "NullReferenceException: Object reference not set to an instance of an object".
    I also tried to debug with Visual Studio - but this exception is not catched here. Every other exception is.

    I guess any of my scripts or plugins is the reason for this behavior. But no scripts or plugins are triggered in this ABSOLUTE empty scene. So whats causing the Nullref? Maybe some static event?
    I tested Unity 2022 and 2023.

    The exception is also in the build - so the reason is not the editor.

    When creating a Visual Studio solution the only catchable exception I'm getting is the following:

    upload_2023-2-22_15-29-53.png

    However, the other NullRef is still logged in the players log.

    Any ideas are welcome! :)

    -Axel
     

    Attached Files:

    Last edited: Feb 22, 2023
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Does it persist after resetting your layout? I wonder if it's some weird problem in editor-land.
     
  3. Axel-F

    Axel-F

    Joined:
    Mar 20, 2009
    Posts:
    223
    Found it! It was a function that was triggered with
    Code (CSharp):
    1. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
    Phew...that was hard to find...

    I triggered a function which set the games resolution this way. Seems this was a bad idea...
     
    chemicalcrux likes this.
  4. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    I think the graphics-backend might not be initialized before the splashscreen loads.