Godot game freezing randomly

Godot V. 4.1.3 Mono

Hi, as the title reads, my game is randomly freezing, both when played from the editor, and in the windows build version, this happens on devices other than my own. I’ve been trying to find the cause for the last day, but cannot for the life of me find it. I’ve tried to check every single loop, while, for, and foreach to make sure that I am not getting stuck in an infinite loop, I’ve tried to check the process function of all of the objects in the scene, to try and maybe find a specific object that is causing the issue. I’ve tried to use F7 to pause the game, but weirdly enough pressing F7 doesn’t show the line i paused at, and when the game freezes, it cannot be paused with F7 or the pause button, the debugger just says that the game is still executing just fine. I’ve run the game from the command prompt with --verbose, and got no error or anything from it, I’ve tried to just wait it out, I waited for 3 minutes and it was still frozen.

A quick list of other tests I did:

  • I ran the game for well over 30 minutes, just letting it sit there and run, and weirdly enough it did not freeze once.
  • I ran the game where it would continually go through enemy waves, to see if it was related to that, for well over 30 minutes, it did not freeze.
  • However when I ran the game by itself and moved the player during it, it DID freeze.

On that note, whenever the game crashed I did notice that it was just before the player objects physics process function got called. The player object is a characterbody2D obviously, and I’m starting to think that maybe it’s some weird fringe physics issue but I don’t know. The problem is not replicable by the way, it’s happened within the first 15 seconds, or after playing for a bit over 15 minutes, and there is seemingly no patterns to when it happens. Also, it seems to only happen within waves, but that’s probably just a coincidence as you spend more time in waves then not. Any help will be appreciated, this is the first game that it’s looking like I’ll actually complete, but with this bug that hope is going down the drain.

moved the player during it

did you check your input movement? it freezes when you move the player, so it could be your input event has something contributing to the freezing

What would I check with regards to the input? Also, as I said the physics process function goes through just fine, it doesn’t get stuck in the middle of the function or anything so I doubt it but will check anyway.

like try to spam key or any move to any direction, i dont know how the player movement works too, so i just assumed.

wave, as in when the monster is spawning a lot at once?

Yeah, I already tried playing the game and just moving left and right continuously, it did freeze, but again it’s nothing within the process function I don’t think

Yeah, I just have a timer spawning enemies every 2 seconds for a set amount of enemies each wave, once they’re dead it takes 10 seconds for the next wave to start, and so on.

i see, did you try disabling the wave and just let your character move freely to confirm if it’s not the input. then try to spawn only 1 enemy per wave. see if any of it still freezes

Yeah, I didn’t describe it too well but: I’ve disable the wave/spawning system and waited for 30 minutes not moving, and no freeze but that’s probably because the player wasn’t moving. I made it so that only 1 enemy would spawn and neither the player or the enemy could kill the other, and left it for more than 30 minutes, no freeze. And finally I tried to only spawn one enemy per wave that would promptly die, making waves continue on with no input for over 30 minutes, and no freeze.

I can try to disable the spawning and just move but I think I’ve already separated the freezing from the enemy spawning/wave system

the enemy has CharacterBody2D too right? how about you spawn them a lot at once (idk how in the position you spawn each one of them tho). like 100 something, if it crash/freeze then it could be too much collision detected on one spot

Not sure if it was the right move but the enemies are RigidBody2Ds. This is my second game with Godot so I’m still learning after coming from Unity. Also, I’ve tried to spawn ridiculous amounts of enemies for fun before, but it did not freeze/crash.

now again what makes it freeze… not input, not spawning, not collision,??
how they are dead btw? just queue_free()?

I have a List in the spawning script that keeps track to know when all the enemies are dead, and when they die they remove themselves from the list and just use queue free. And that’s the thing, I don’t know what’s causing the issue, I’ve gone through everything I can so far and can’t seem to find anything out.

i see, do you remove_child before queue_free()?

No I don’t.

prob that the issue, enemy_container.remove_child(the_dead_enemy) first, then queue_free()

Could be, but I’ll note that this is a really new issue, in previous versions of the game, there was no freezing. Will test that now though.

Just added in the removechild() part, and the game still froze.

i see, do you have any animation (animationPlayer or tween or both) on the enemy?