Strange behavior with the link to Game Status object

I’ve gone through this step of the tutorial, and I have run into this strange problem.

The Block’s Game Status object link does not seem to work once I move from Level 1 to Level 2. For example, in Level 1 I will get 100 points. I move to Level 2, 100 points is still displayed, but it is no longer updating because the blocks don’t have a link to Game Status.

If I pause the game, I see the inspector showing “Missing (Game Status)”

What completely confuses me is if I were to start from the Level 2 Scene, go to Game over, then game start, then back to Scene 1… then everything works! Once I am done Scene 1, Scene 2 works perfectly.

This ONLY works when I’m starting from level 2. Starting from any other scene has the same bug.

I scrubbed through my level 1 and level 2 scenes, and don’t see anything odd. All prefabs don’t have any changes.

1 Like

Hi dy77,

Are there any error messages in the console that you could share with us?

I am guessing that maybe there is an issue with the GameSession game object on Level 1. Since you have a prefab of it, I would suggest you remove the game object from your Level 1 scene and copy in the prefab again. Before you do that though, check the GameSession game objects in both Level 1 and Level 2 and check if there are any bold entries, as these are changes you have made to the game object in the scene and not the prefab (and you might want to keep some of these custom changes).

If that doesn’t work, go to your GameSession game object in Level 2 and apply the changes of that GameObject to the prefab (select the GameSession game object, go to the inspector and on the top right click “apply”).

It sounds like what is happening is that a GameSession object is being created in Level 2 and the Singleton Pattern is carrying forward the GameSession object to scenes down your scene hierarchy. However, it is not properly doing it from Level 1.

Also, I just realized you mentioned a Game Status object… later Rick renames it to Game Session and makes a few changes. Maybe in the next lecture(s) you’ll find a solution?

If you want to be really sure, I suggest you download the game files from the link in Github and compare your scripts and Unity content to Rick’s. It’s helped me fix a few errors I’ve made.

I hope this helps!

I found this link which describes an issue that sounds very similar to yours:

I had the exact same problem. I spent a couple hours going through the scripts, etc. and couldn’t figure it out. Phil’s link did the trick, by deleting the GameStatus object from the later scenes the score now updates properly. My guess is that somehow the Level script was attaching to the second GameStatus object just before it destroyed itself. It seems like it would throw an exception when it tried to call a method on that (now destroyed) object but it didn’t seem to, so I’m still a little confused. But at least it works! Thanks.

Thanks for all the replies! After moving a few more lessons forward, I noticed that the code changed and the new code works. I don’t think it was explicitly called out though.

Basically instead of creating a link to the Game Session object at Start(), the code now looks for it on every 2D Collision. This seems to bypass the race conditions when doing it only at Start().

Some of the other solutions posted works as well, and are probably more efficient since it doesn’t do it on every collision.

Privacy & Terms