Rigidbody2D is frozen at first.

So I’ve got a movement script, and I have a Rigidbody2D. I did a descent amount of testing (not really) and found that it’s not the movement script that’s the problem, as it happens with other scripts (for movement). I also have a script for the pause menu, which - among other things - disables the player movement script when the pause menu is turned on, and turns it back on when the menu is turned off.

This also isn’t the problem, as that’s all it does with the player’s movement. However it may somehow be bypassing the issue, because when I try to disable and re-enable the script manually (while the game is running), nothing happens. Whereas when I open the menu, and close it, the rigidbody drops to the ground and I can control it.

I tried doing the following to pinpoint the issue, and fix it:

  • Disable the pause menu script.
  • Change the “Sleeping Mode” of the Rigidbody2D to “Never Sleep” instead of “Start Awake”.
  • Enable the movement script in the pause menu script, inside both “Awake” and “Start” (separately, and then together).
  • Reset the Rigidbody2D, as I have been playing with some settings, and wanted to make sure it wasn’t me breaking stuff.

I have not messed around with any of the “Physics 2D” settings in the project options, other than decreasing the “Default Contact Offset” as much as possible (because there was a tiny, empty line between colliding sprites). I reset that too, but it didn’t fix anything.

There is nothing currently at the same z value as the player, although that shouldn’t affect sprites. I checked actually, and it doesn’t. The player can still be technically inside a wall, and the physics still work after doing the pause menu enable/disable.

Just for the sake of it, here are the Rigidbody2D setup:
3206045--245242--upload_2017-9-2_9-51-2.png

And the “Physics 2D” window:

I also tried unchecking all the collision matrix boxes for the “Player” but that doesn’t seem to affect sprites either.

Has anyone got any idea what could be causing this? Let me know if you need some more information.

Bump. I’m really suspecting something in my code to be wrong, but I have no idea what. This type of stuff never happened before.

Sounds like a sleeping problem, but I see that you tried those settings already.

Try this though: give the script a “void OnEnable()” method and in that method, find your rigidbody reference and do an .AddForce(Vector2.zero); This will execute when you are re-enabled.

If that fixes it, then it really was asleep, which I speculate might happen with certain enable/disable combinations.

Still freezes.

Gonna create a new project, and copy over all the files to see if it still freezes. Maybe it’s something I changed in the physics settings.

Update: Didn’t freeze in a new project. Tried resetting Physics 2D Settings and it still freezes.

My understanding of the problem : Your character works but is frozen momentarily at the start.

The problem could possibly be the order of the scripts affecting player movement. To my knowledge Rigidbodies are moved in FixedUpdate. If you’re scripts are affecting them at a different point it could result in strange movement. This diagram shows the order of execution.

As well you can manually reorder when scripts are called with the Script Execution Order settings

Hope this helps! :slight_smile:

EDIT

  • I meant FixedUpdate rather than LateUpdate

Well like I said in my last post, it didn’t freeze when I tested it in a new project. I copied over everything from the assets folder. I opened the same scene, and it didn’t freeze. So it’s definitely nothing with any of my assets.

And yes, the character works, but the rigidbody gets frozen. I can still turn the player based on movement input.

Also, I only have one script that affects the rigidbody, and it runs in FixedUpdate.

I’m 99% sure it’s something in the project settings, but don’t know what. I already tried the Physics 2D like I also said.

In both projects, go to Edit → ProjectSettings → Editor and change Asset Serialization mode to Force Text.

Now use your favorite text compare program to compare the differences in the files inside of ProjectSettings directory, such as the ones like Physics2DSettings.asset, see what is different. Often you can gain some insight.

ALSO: you should always use source control (I recommend git) while working, and that means you definitely want Force Text mode on so you can SEE what changed in each revision and make informed decisions about whether to commit the change each time.

2 Likes

After going through almost the whole folder (from top to bottom), and an encounter with a spider in my room (I have arachnophobia), I found out it was the TimeSettings of all things. The pause menu script sets timeScale to 0 in order for the game to actually “pause”, but I never even once clicked on Time in the settings.

Basically, in the settings, the time scale was set to 0. Which now explains why I was able to bypass the issue by pausing and unpausing the game.

Thank you everyone for the help. :slight_smile:

3 Likes

Ha, yes, I have been there, I have done that. Welcome to the club!

2 Likes