I have a blank/black screen when I load my levels

Hey yall! To preface, I’m a beginner developer, and I don’t really know how to code in Unity yet, but I am learning how. Now, I’m following along with a course on coursera, and I run into this strange issue. When I click play on my 2D shooter game under main menu, and I hit the new game button, I can play the game like normal, but when I load next level, I get this strange warning that I have 3 enemies to defeat, but 0 enemies at the start. sometimes, I get a blank/black screen with projectiles shooting. I hear the game audio perfectly, but I don’t see anything. I’ve tried adjusting the sorting layers to say “background,” I’ve tried adding more enemies in my level2, but I just can’t seem to get rid of this warning. Any advice would be greatly appreciated. Thanks a ton

First level works, second level doesn’t and it’s a GameManager-like function?

That sounds like a defective singleton (see below) to me, but you can find out through debugging.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

Some super-simple Singleton examples to take and modify:

Simple Unity3D Singleton (no predefined data):

Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:

These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance

Alternately you could start one up with a [RuntimeInitializeOnLoad] attribute.

There is never a reason to drag a GameObject into a scene if it will be DontDestroyOnLoad.

If you do:

  • you may drag it into something else that isn’t DDOL. FAIL
  • you may drag something else into it that isn’t DDOL. FAIL

Just DO NOT drag anything into a scene that will be marked DontDestroyOnLoad. Just Don’t Do It!

1 Like

Appreciate you a ton Kurt.