I recently started making a game in Godot using C#, and I thought I’d share a potential pitfall that I ran into, which caused _Ready() to fire twice. I couldn’t find an example of this specific mistake anywhere else, so I thought I’d contribute my findings to help people troubleshoot.
When making a new scene, I connected the signal manually like this, thinking that I needed to in order to make use of the function. In fact, you’re not supposed to do that, and doing so will cause the method to fire twice, as I found out after trying to debug for like two hours.
So here’s what’s going on. ready() is a signal and _ready() (or_Ready()in C#) is a function. When the _ready()private function (and some other things like @onready variables) are complete, the readypublic signal is sent. Since the signal only fires once and isn’t directly tied to the end of the _ready() function executing, you didn’t end up in an endless loop.
I strongly recommend you follow these two tutorials from the documentation, as it will help orient you to the engine and prevent further confusion like that for you in the basic functioning of Godot:
I actually followed the 2D tutorial first before making this error in another project I started. Perhaps I didn’t read the explanation carefully enough?
I’ve been programming professionally for decades now and I understand the desire to skip through a tutorial and get the gist so you can start coding. It’s a really bad habit. It’s one I had to break myself of. When you are learning something new - even if it’s how to use a feature you already know - follow the instructions exactly and read everything. Then, when you are done - and it’s working, start making changes.
This lesson will benefit you greatly in life, whether it’s learning programming, sports, writing, or any other skill. Learn from the teacher, then take what you want and leave the rest.
There’s lots of things you are not supposed to do with C#, which is either not documented at all , or is not explained very well in the C# documentation.
That’s exactly why I posted my findings here, so people who make the same sort of “school-boy error” can find their problem and fix it quickly. I definitely had a “facepalm” moment when I figured out what I was doing wrong.