Reloading a Scene Increases Gravity Acted on a Player
I have been working on a 3D game where a player drives away from another vehicle, once the player reaches the end of the level they are able to reset the level. However, with each time the level is reloaded the force of gravity on every object in the game is increased.
I am using SceneManager.LoadScene to load the scene again. I removed setting the mass of the player in the start method in case that was what was causing it. I also looked for any information on why this would be so, however nobody I have seen has encountered this problem. Does anybody know why this might be?
Does any script use Physics.gravity? Also after reloading, check that no script got a duplicate script, or triplicate after two reloadings.
Answer by cagozz · Feb 24, 2021 at 02:17 PM
When I pressed spacebar, I wanted to restart game. I faced with same problem, and I solved problem by equalizing "Physics.gravity" to default value. (Default value = 9.8 because gravity acceleration)
if (Input.GetKeyDown(KeyCode.Space) && gameOver)
{
Physics.gravity = new Vector3(0, -9.8F, 0);
SceneManager.LoadScene("Challenge 3");
}
This helped me figure it out. I was multiplying Physics.gravity by a variable in start. I added a line to divide it by the same variable just before reloading the scene and it now it works.
Thank you!
Answer by foreternallove1 · Dec 18, 2020 at 11:28 AM
@Uwantarefund did you find any solution for this? I am also encountering the same problem. Every time a scene is reloaded, it feels like gravity increased and gets worse every reload.
Answer by melazzeh · Feb 06, 2021 at 11:54 PM
I am having the exact same problem. Can someone from Unity help please?
Answer by Croutflateam · Feb 18, 2021 at 02:55 PM
Hi, Had the same problem and fixed it by removing the gravity modifier in the start method. To flag this I opened the project settings and checked what number changed each time I reloaded a scene and found the corresponding line of code. Basically each time I was reloading the scene it applied the start method that modified gravity, making it worse every time. ,Hey! Had the same issue and found a fix for me. As a beginner I was using a lot Unity resources and combining them, one of them being to have a float for gravity mod with a start method that updated physics2D.gravity. But combined with reload scene, it actually increased gravity every time. My advice, check your start method for that kind of code, and instead edit the gravity yourself in project preferences.