Godot Version
4.3
Question
In my project, I have a small collection of scenes which are the enemies of my game. Each scene is for a specific type of enemy, they all have a root node of type “Enemy”, which is a class I created that extends CharacterBody2D, and children which are the various components of the enemy, such as an AnimatedSprite2D, CollisionShape2D, and various areas, shapecasts, and raycasts that it uses to sense things about its environment. Here is an example of what one of the enemy’s scene tree looks like:
The way my project works is that each “room” in the game is scene, and inside that scene is where I instantiate the enemy scenes so that they appear in the room. The room scenes can get quite complex, but they are basically just a structure of nodes to organize all the objects each room requires. Here is what one looks like with a single enemy placed inside:
I’ve been working on my project with this structure for many months now, and have had no issues placing my enemies into rooms. But very recently, I have encountered an issue where placing enemies in a room will cause the running window of the project to become “not responding”, and will freeze up until I close it. No errors are thrown in the console at any point. To eliminate the possibility that some sort of coding issue could be causing this (infinite while loop or something of that nature), I commented out all of the code for every enemy. So now the actual enemy scripts are completely empty, All that I have is what you see in the enemy scene tree. Yet the game still freezing on run whenever there is any enemy within the scene. So I made a new enemy which is completely empty, all it has is the root node of type “Enemy” (which is now a script that is completely blank, just extending CharacterBody2D and declaring itself as a class Enemy), and a simple CollisionShape2D, like so:
When I place an instance of this minimal enemy scene in a room, the game will no longer freeze on run and everything works as intended. This occurs even when there are other enemies in this room which before were freezing the game. Removing this minimal enemy will once again cause the game to freeze.
So the below room will run as intended:
But this room will freeze, with the only difference being that this minimal enemy scene has been removed:
There are no references to either of these enemies anywhere else, nor do they interact with each other in any way. And keep in mind all the scripts on both enemies are entirely blank, they do nothing at all. So you can imagine my confusion at why adding a scene fixes my problem, when it doesn’t make any sense for it to do so.
before trying anything else, I attempting reloading all saved scenes, restarting the editor, restarting my computer, and deleting the .godot folder to force the project to reimport everything. No change.
What I eventually discovered by playing around with the children of enemy scene was that if I were to copy-paste all the children of any problematic enemy to a temporary empty scene, delete them all from the original enemy, and then copy-paste them all back, the enemy would no longer cause any issues.
I really don’t know what to think of this issue and why simply copy-pasting nodes around fixes it, and why something like that does work when all the typically troubleshooting methods did not. I am also unable to create a minimal reproduction project, but it did consistently happen in my project with all of my enemy scenes, despite there being nothing particularly unique or complex to them.
If anyone has had experience with a similar issue or has any insight into why or how this happened, and especially how I can prevent this from happening in the future, I would love to know.