Using 2 scenes massively hurts performance - why ?
I've been working on my game for a while and so far it's just dumped you straight in the game when you start. I thought I'd use another scene to add a title sequence... just to give things a bit of polish and things.
The opening is reasonably computationally intense. I created a logo that's split between 256 boxes which I stack up into a wall, and then smash it up in slow motion and have all the fun physics going on. At the end of all of this, my code simply executes the line -
SceneManager.LoadScene("Main Game");
... this loads up the original scene I was working on and all continues on as normal. Or so I thought - when I did a build to test everything out, I noticed the frame rate on my main game felt really choppy. I went back to a previous version and it was super smooth.
I tried running the second scene on it's own, and it's lovely and smooth again, but as soon as this is loaded as the second scene it all goes to pot. I used the profile manager to record what was going on - this first screen shot is the second scene running on it's own
and this next one is the the same scene after loading in
You can see that massive spike in the physics calls - and it never goes down, so my games goes from running very smoothly at a high frame rate to barely 15fps. I checked the docs for how loadscene works and as I understand it, it should (by default) destroy all the objects in that first scene when it loads the second.
I stuck in a few debug statements to check the SceneManager.sceneCount value, and it does go to 2 for an instant in the last line of the first scenes script (after the load call) but in the first code of the new scene its back to 1.
My only guess is that to spike this much it means that that previous scenes ridigbody physics objects are still there somewhere and causing this overhead... else I can't explain why else I'd see the spike in physics calls and the performance hit.
Any ideas on what I can do ?
Just as some additional info - also through the profiling tool I noticed that the number of FixedUpdate.PhysicsFixedUpdate threads (assu$$anonymous$$g they are threads) seems to jump exponentially.
If I run scene 2 on it's own, I get around 5 of these. If I run scene 1 it gets around 20 of them, but then if I let scene 1 load scene 2 we have just over 100 of these taking up the bulk of the processing.
I'm using Unity 2018.4.11f1
Your answer
Follow this Question
Related Questions
Performace issue with game??? 0 Answers
Performance Issue While Near One Specific Object 0 Answers
Bad performance with Physics.Processing and impossible to find the reason why. 1 Answer
Getting low fps on a very simple scene 0 Answers
How do I load additive scenes with SceneManager? Loading a new Scene as Additive breaks Physics? 0 Answers