r/UnityHelp • • Dec 14 '22

Reference becomes null after it's used once and I don't know why

Post image
3 Upvotes

6 comments sorted by

1

u/JacobiWanKenobii Dec 14 '22

I'm trying to make a panel that's deactivated at first until you set up some options, and then it appears. I've tried multiple ways to solve it (setting localscale to 0, SetActive, moving it off-screen, etc.), but the only conclusion that I've been able to draw is that once deactivate() is called, the reference becomes null. Even having 2 separate references to the panel doesn't work, as they both become null. I've been trying to find an answer for the past few days, but I haven't found anyone who has had the same problem and has a solution for it.

2

u/SQWolker Dec 14 '22

In options you call "activate" method? And why you need 2 GameObjects?

1

u/JacobiWanKenobii Dec 14 '22

Te 2 game objects were the latest experiment to try to solve the issue, I've also had 1 GameObject and gameObject.SetActive(false/true) for both of the functions, but all those had the same problem. I have another function call the activate method once the options are set up, but that throws the Null Reference Exception.

1

u/SQWolker Dec 14 '22

Maybe you change scene and your battleHUD destoys on Load?

1

u/[deleted] Dec 14 '22

Are you dragging the Gameobject from the scene into the inspector?