Null Reference in Task.OnEnd() when stopping play Unity 2020.1

chaneynow

New member
I have an odd thing that just started occurring after I upgraded to Unity 2020.1.

I have a Random occurrence of Null Reference exceptions when I stop play that always occurs on the override OnEnd() method in Tasks that were running when I stopped play. The Null Reference always refers to a GameManager.Instance Singleton gameobject (DontDestroyOnLoad). I use it for some static references to settings and scriptableObjects. I access the GameManger. Instance in OnEnd() because there are some settings that need to be reset when those tasks end.

I can avoid the Null Refs upon Quit if I do Null checks in every OnEnd() task bypassing the GameManager.Instance but that seems hacky.
Code:
if (GM.Instance == null)
                Debug.Log("GameManager Instance is Null");
            else
            {
                charCapsuleCollider.material = GM.Instance.ColSettings.defaultEnemy;
                animator.SetBool(GM.Instance.GMSettings.climb, false);
            }

What I don't understand is why OnEnd() would still be running after OnApplicationQuit() has been called.


Thanks
Allan
 

Justin

Administrator
Staff member
When OnApplicationQuit is called the behavior tree stops which then calls OnEnd. I'm guessing that your singleton is being destroyed before the behavior tree so that's why you are getting the exception.
 

chaneynow

New member
Yes Unity randomly chooses which gameobjects to destroy from the scene thus it's an error that occurs randomly.

It's just very strange that this only started with the upgrade to 2020.1.

I'm still researching what's going on but thanks for your reply.
 
Top