Newbie question - multiple scenes loaded in at once

Hi there, I’ve been interested in coding for several years and I’ve learned a few rudimentary languages, just started trying out Unity and C# last week and I’ve been following a tutorial to learn the basics, though I have been making changes to make it more my own. I’m usually pretty good at finding answers to my questions with coding, but this one for some reason has me stumped and I think it’s more of a unity thing than a coding thing.
My issue is that I finally got to the point where I can start adding in new levels and messing around with that, added in a level complete screen with code telling the scene manager to load the next scene when an input is given, but now that that is there and I’ve duplicated my first scene to have something to load from then on the first time I load up the game every scene loads in at once, only when the player collides with an obstacle and it reloads the scene does it start working normally, from that point on if I fail or succeed it behaves as I want it to and even goes to the next scene with no issues if you beat the first scene.

Unfortunately I’m not at my computer anymore to actually grab my code but I’m not sure it’s an issue with the code in the first place, any help would be appreciated, thanks!

Not sure how clear it was but when I click play there are 2 of every item in the world at once and anything with a RigidBody immediately separates and goes flying

Is that the problem? If so, that’s just your RigidBody properties, you can always set constrains for position and rotation, you can find that under ‘constraints’ on the RigidBody.

I mean isn’t it a problem? If I set limits to the obstacle’s RBs I won’t be able to have the player impact them a fling them around which I think is cool, and it’s not just duplicating physical objects, it’s duplicating everything, camera and lighting, etc.

It’s making a bunch of errors pop up that there are multiple of things there shouldn’t be multiple of, audio listeners and the like, even if I remove the duplicate specific items and lock the rigidbody of each thing the player is also there and that needs to be moved around, if I were to remove the 2nd one then when I load into scene 2 there won’t be a player to use

Sounds like you’re doing something wrong additive-loading-wise. Time to debug it! (see bottom of this post)

Here’s some random notes on the process:

Additive scene loading is one possible solution:

https://discussions.unity.com/t/820920/2
https://discussions.unity.com/t/820920/4

https://discussions.unity.com/t/824447/2

A multi-scene loader thingy:

https://pastebin.com/Vecczt5Q

My typical Scene Loader:

https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3

Other notes on additive scene loading:

https://discussions.unity.com/t/805654/2

Timing of scene loading:

https://discussions.unity.com/t/813922/2

Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It’s a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

Two similar examples of checking if everything is ready to go:

https://discussions.unity.com/t/840487/10

https://discussions.unity.com/t/851480/4

To get started on debugging:

You must find a way to get the information you need in order to reason about what the problem is.

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

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this);

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: https://discussions.unity.com/t/700551 or this answer for Android: https://discussions.unity.com/t/699654

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://discussions.unity.com/t/839300/3

When in doubt, print it out!™

Note: the print() function is an alias for Debug.Log() provided by the MonoBehaviour class.

You can indeed have multiple scenes loaded if you use the SceneMode.Additive parameter.

You can keep track of what’s going on with these:

        protected override void OnEnable()
        {
// other stuff...
            SceneManager.sceneLoaded += LoadScene;
            SceneManager.sceneUnloaded += UnloadScene;

Thanks for the advice!
I did actually figure it out in the middle of setting up the debugging process, looks like I misfollowed the tutorial and I just don’t know unity well enough yet, I only had the one scene so when I had the 2nd scene also up in the hierarchy it didn’t strike me as odd.
I did however use the debug method to figure out another issue I was having, and I’m sure the more I use it the more I’ll just naturally add it in, thanks again!