Godot Debugging Techniques EVERY Dev Should Know
Vložit
- čas přidán 19. 06. 2024
- In this Godot 4 tutorial, learn several debugging tips and techniques that are better than print()ing to the console. Learn about different print/error statements, use the Scene Tree to debug, and get a breakdown of the Godot debugger itself. With these and a few other Godot features you'll go from caveman debugging to hunting down bugs like a veteran gamedev. You can do this ❤️ 💪
0:00 - Intro
0:21 - Print alternatives
2:41 - Remote Scene Tree
3:59 - Always on Top
6:57 - The Debugger
9:51 - Deleting Save Files
11:54 - Stepping Through Code
15:04 - Visual Debugging
15:57 - Outro
#godot4 #debugging #debugger #gdscript #gamedev #gamedevelopment - Hry
Great tips! I worry that some viewers might not realise that "always on top" affects the behaviour of their final game, though.
Oh really? I honestly thought that was just an editor setting. 😳 Thank you for letting me know.
Out of all the courses I feel like I should have had in my computer science degree, properly using a debugger really should have been near the top
You and me both, but it’s never too late to add to your bag of tricks (or mine)! 🤜🤛
print("It's working!")
That would have been a much shorter video 🤣
@@whannabi
if not found_errors:
get_tree().quit(ExitCodes.ERROR_NOT_FOUND)
my biggest tip is using *assert(condition: bool, message: str)* for when critical stuff fails because it also stops the game if the condition doesn't fail.
I use this primarily when initializing things, or when really unexpected behavior happens.
here's an example from my game
static func setup_state_machine(node):
assert(StateMachine.is_configured_properly(node), "%s doesn't have the necessary variables setup to be compatible with the State Machine" % node)
node._states_node = node.get_node("states")
assert(node._states_node != null, "%s requires a node called 'states' containing the states for the State Machine to work properly" % node)
node._current_state = node._states_node.get_child(0)
node._current_state.set_parent(node)
node._current_state.on_state_enter()
node._current_state.is_active = true
node._last_state = node._current_state
(I have a class that allows me to an attach a state machine to any object, and here I added 2 asserts to make sure that before the program moves forward, I didn't misconfigure something)
This is great! I actually had assert in the first cut but I think I chopped it for time (or because it’s going in the follow up to this video, I can’t recall 🤣- have to check my notes). Thank you for sharing this!!!
One thing I found insanely useful is the "misc" tab in the debugger.
I made a little game for a game jam, where you interacted alot with interfaces.
Lots of small mini games, where you had drag stuff, click stuff, etc
And often it happenend that I forgot to put "Mouse ignore" on a gui element.
In the misc tab of the debugger, you get the information which element you clicked last :D
Saved me so much time!
Great video! I immediatly added the "On Top" feature to my project. xD I always drag my window on a different display, and back, different frame rates... it is annoying. The On Top Feature saves me all of that!
I believe there’s a setting that will also force the game to open on a specific monitor in a multi monitor setup. I feel like someone mentioned that in a comment 🤔 Thanks for watching and saying hello 👋
4:44 on a similar note to always on top, if you have a multi monitor setup, you can set it to always launch on a specific screen and keep your editor on the other. Then you’ll have the full editor while still seeing the game
Oooh, that’s a great tip! Thanks for sharing that ❤️
Very useful. Thanks for putting this together!
Thank you for watching 🙏🙏🙏
Man this was good info, you have saved of time i would have spent knowing debugging in godot editor. thanks mate, subscried.
Thank you, my friend! Looking forward to seeing what you’re working on!
I was writing a function the other day with a monstrous if-else tree. As a joke between me and myself, I put `print("PEBCAK")` into an if branch that should never run.
Seeing that output every frame was... humbling.
Haha. Programming is definitely a humbling experience. I love that you’re having some fun with it.
This is so incredibly helpful, thank you!
You are so incredibly welcome. Thank you ❤️
I NEED THIS! Thank you for uploading this video
🥹 Thank you 🙏 that’s really nice to hear. I’m glad you doing it helpful.
Exactly what I needed--thank you! 🙏
Aw thank you! That made my day. ❤️
Very helpful video! Thank you!
Thank you so much 🙏❤️
It was super informative, ty very much man!!
You’re welcome very much 🙏
Thanks for all the options!
You’re welcome. Thanks for watching!
This suggestion is only useful for functions that you want to step into but don't want to go through every single line every time. If you have a troublesome area that you need to debug with breakpoints, I recommend setting a breakpoint at the start and then another breakpoint after every line that has a called function that you may be interested in stepping into. This way, you can step into functions of interest and then use continue to go back to where you were without losing your place in code-time. Going off your demonstrated example, if pushing left on that particular tile was the problem, hitting continue would advance you past the trouble spot. Doing it this way allows you to easily go back to where you were without advancing time.
Excellent point! 🙌
Hey man, great video! After watching, I want to make a video going more in depth into every print function. I'll link this video in the description!
Oh right on! That would be great. Let me know when it’s up and I’ll link back. I follow your channel (though probably from my personal account) Great stuff 🤜🤛
You should post this in the Godot forums, I think people would have less questions if they understand basic debugging techniques.
That’s a great idea. I honestly hadn’t considered that 🤦♂️🤣 Thank you!
Great suggestion and done!
forum.godotengine.org/t/using-the-godot-debugger/49576
Extremely helpful!!
Thanks for watching! I appreciate you 🙏
Really cool video, those auto remote scene switch and always on top parameters are definitely gonna make my life easier. Thanks!
🥹 I recently learned there’s a known bug in the Remote SceneTree that can cause more complex games to stutter a bit while open. So if you experience some odd lag, keep that in mind. I still thing auto-open is the way to go but until they fix that, just keep an eye out. I’ve never experienced it myself so I don’t know what it takes to trigger that bug.
@@baconandgames Oh alright I'll be careful then, thanks for the heads up mate!
@darenn-keller yeah I mean, I’ve never seen it myself so I can’t say how far you have to push Godot before it turns up or how common it is. 🤷♂️ Someone in my comments gave me a heads up. Just passing it along! Hope you share your game with us when you’re ready!
great video. Thanks for uploading
Thanks for watching! 🙏 Plenty more coming.
Cool !!! Very save !!!
Thank you for this video.
It’s my pleasure! Thank you for watching 🙏❤️
Thank you. I'm learning Godot!
Me too! 😬
What I also found useful was utilising Input.set_mouse_mode to capture and uncapture the mouse when clicking the viewport and pressing esc respectively. This is good for 3d games which use your mouse input directly.
Oh interesting! Thanks for the tip 🤜🤛
Quality content: subscribed :)!
❤️🙏
Nice work. Please keep it up! :)
Deal! Thanks for watching!
Three minutes in and auto switch to remote has changed my life. Thank you!
p.s. I agree with the other commenter about volume, ended up with my laptop speakers at 100% which isn't ideal. Great video though!
It’s a revelation, isn’t it? There are so many setting like that in Godot to make your life easier that I’m surprised aren’t on by default (not picking on the good folks working on it). I appreciate the feedback on volume, truly. I can only improve if I get feedback! Thanks for watching 🙏
Debug window to call whatever stuff helps you test is really useful too. I like to have separate windows than my main application too
Can you provide more info on this? I’m not sure I fully understand but I’d love to know more 🙏
I subscribed when you said "cave person", keep up the good work 😂
And my parents told me being a smartass would get me in trouble. 🤣 Thanks! 🙏
Nice tips 👌
🙏
Thank you!
You’re welcome!
I had no idea about "Always on Top" and "Automatically Switch to Remote". Thank you!
You’re welcome! Those are game changers for me. It’s wild how many settings there are like that to turn on or off.
When it comes to visual debugging you can also create your own. When debugging complex systems this can come in handy. I'm programming a complete platforming system and when you want to start debugging some of the more complex movement and jump algorithm, having that stuff on screen at a specific position really helps, especially when you keep track of 5 to 10 different variables.
That’s super cool! I love this. 👏
@@baconandgames Thanks ! I feel like this is also kind of its own thing. It has cons and pros compared to other methods. It's longer to implement and it means either signalling or finding a good non destructive way to update the UI but it lets you track multiple states and components in real time.
I'm glad there's some good debugging resources for Godot because it's probably an area where many beginners will struggle ! Taught me a couple of Godot-specific things too so thanks for that :)
Hey you know what… that’s making games. Pros and cons to every choice and there’s not always a “right” way. I always appreciate hearing how others approach stuff because it helps me grow too! Thanks for the comments and for watching. I hope you stick around and continue to teach me and others 🤜🤛
@@baconandgames So true ! Well thanks for the video and the tips as well and I'll definitely keep an eye out ;)
🥹🙏
Make validation script tool could be great too, since we can have tooltip and icon on the editor if I remember well. Silly mistake of initialisation are more friendly that way.
That’s a neat idea! 🙏
I can't believe you didn't mention assertions. These are very good and quite important blocks to throw in for code you generally expect to work (you design rest of your code as whatever you check with assertion, couldn't happen). Assertion works like permanent breakpoint that activates only when condition is not met. You can see what's inside your objects/tree as well.
Agree with push_error, great tool. Built my testing framework around it to instantly be able to move around stack and see what's inside. Great tools for debugging.
As for print as it also has it's own use, I can only suggest to try and use it's % syntax, it's easy to include many variables and you can print whatever type you want with %s + str(var).
Assert is coming in the next video 😉 I had it in this one but cut it for time and because I like how it fits with the next one. You make a good point though. Thanks for watching!
thank you!
🤜🤛
thanks a lot :)
Happy to help. Thanks for watching!
very helpful.
Glad it was helpful!
you gained a subscriber!
Welcome and thank you! 🙏❤️
*sees "Always On Top option*
oh my goooooooooooood
Just keep in mind this setting affects the final product. So if you only want this during development (how I use it) make sure you turn it off before the final export.
One thing I'd like to learn is a more efficient way to debug when using network code. I find it hard as to not even touch break points on my online scenes.
You and me both! I haven’t found a great way to simulate network lag locally either. I found one decent bit of code for that on GitHub but I was hoping there’s a built in feature for this that I just haven’t found yet. I wish I had resources for you on that but I’ll keep my eyes open. Let me know if you crack it. 💪
10 years of software engineering. And i finally learned what that damned red dot that's present in a lot of IDE does! SMH.
🤣 Well… you still learned it sooner than I did. Thanks for watching 🙏
Oh yeah I really love cave person debugging cause I’m from 1500 BCE
🤣
Btw, if anything, just to address what the others are saying, i played the vid at 45% volume. At that level, it's quaint for me.
Though in contrast, i think this is just a by-product of volume mgmt of most big youtubers in general. Most are quite loud so i play vids at around 12-25% most times.
If we use Linus Tech Tips as a benchmark to compare against -
To get both vids to feel to be at the same audio level, in my speakers:
random LTT vid: 15
this vid: 45
Tested this over and over, calibrating the volume until i get a matching feel. Hope this helps!
This is super helpful, thank you! I will look more closely at volume for this week’s video. 🙏
*Good:* _Debugging technique explanation & demonstration._
*Bad:* _Using _*_string_*_ instead of _*_enum_*_ for those "gateway" export variables._ 😱😱😱
Haha. It’s true. I’m still a little shaky on using enums the way I want in Godot. In fairness, a room could have 50 doors and never repeat a name, like “to-dungeon” or whatever. So I left it flexible but less stable, for sure. If every room only had 1 of 4 doors, like in Zelda, enums make a lot more sense.
In all honesty, were this not just a sample project I’d problem not use enums either. I’d just store a reference to resource that needs to be loaded. No need for that intermediary translation. But yes, in general, hardcoded strings are often a big no-no. I agree 😉
can you do a video showing debugging multiplayer games? i havent found the debugger or inspector to be as useful in debugging synchronization issues or stutter
I don’t have a lot of experience with multiplayer games but I do know a guy who has a youtube channel who is currently making a multiplayer godot game. I’ll see if he’s interested in covering that topic for you :D
@@baconandgames wow thank you!! and thanks for all the great tutorials
How are you defining them globals in the node? Any chance I could take a look at the source for that bit?
Truth be told, this is from a project of mine that’s a bit of a mess. I was just using it to have something to show debugging. But if you give me more detail I’ll be happy to help you out. Which nodes and which globals? I’d be happy to just send you my autoload files, if that would answer your question
@@baconandgames I have the autoload defined and it's a subclass of Node but I'm not sure how you're able to alter the exported vars from the inspector (the push strength in your game, for example). I've tried adding a Node to the scene and the global script to the node but that didn't work. I'm a noob, possibly missing something obvious. Thanks for the reply!
I'm not using any export vars in my autoloads, but that sounds like what you're talking about. Have a look at this page from Godot's docs. docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html
If you're talking about how I edited the strength value in the property inspector, I cover that in the video under Remote Scene Tree. So if export vars isn't what you're after, maybe have a closer look at that section. Hope that helps!
I rewatched the bit about the remote scene tree, I understand now. Thanks a lot for your help!@@baconandgames
And now use your brakpoints to catch whong character speed during gameplay.
Oh, we use print again, but into debug widget.
But it is probably too advanced approach LOL
I saw whatever catches the bugs is fine by me 🐛🧲 😬
Why is CZcams attacking me for no reason with this video
I paid them a LOT of money to target you specifically . So you better watch it, for my sake. Please. I’m begging you. 😅
What exactly does having the remote scene tree activated do? The only thing I get is that the program freezes when I run it
Are you making a 3D game? I know that having the remote scene tree open can slow larger project down and cause issues. But the purpose, for games that can handle it, is to have access to the properties of game objects in real time so you can inspect them live. Otherwise you’re just looking at the author time settings, which serves no purpose during testing. I tend to make games that aren’t heavy, so I’ve never run into issues with auto-loading the remote tree. If you’re having issues with that, I’d avoid auto opening it and instead only switch to it when needed.
@@baconandgames It is a 3D game with a procedural dungeon, I suppose that being so big it is heavier
Yeah. You’re probably hitting the performance issue. You might still be able to use it, but I wouldn’t set it to auto-switch to the remote tree for your game
Just a warning for anyone using "Auto Switch to Remote Scene Tree", having the Remote Scene Tree open can make your game stutter constantly as it's refreshing itself. It was extremely difficult for me to figure out where these stutters were coming from. This issue still hasn't been fixed.
Oh that’s good to know. I’ve never experienced that but I tend to make smaller scale 2D games, so that tracks. I assume those had been logged as a big, yeah? Thanks for mentioning this!
Professional developer here who has programmed for decades. I'm ashamed that I still use print() more often than debugger tools. Maybe this will help push me to break the habit. Thanks.
Don’t be ashamed, I do too! Think of it like anything else, sometimes a hammer is just fine, but it’s nice to know you have a flamethrower when you need it 🤣 The right tool, for the right job 🤜🤛
Person with 1 yr experience - using print for everything.
person with 2 yr experience, finally learned debug tools.
person with 10 yr - just uses print and get job done.
@kishirisu1268 took me way longer to do anything but print. 🤜🤛❤️
if the setup takes longer than setting up a print statement then no I am not saving time
Edit: oh wow it is as fast and it does save time
👏👏👏
Thanks a lot!
P.S. the recording is very quiet, it’s hard to hear
I hadn't noticed that. Thanks, I'll take a look and be sure to make any necessary adjustments in future videos. May I ask... have you found this to be the case with any of my other videos or just this one?
@@baconandgames
Unfortunately, I came across this video through CZcams recommendations, and had not watched the other videos before, but since you asked, I had to watch a couple of them.
On the one hand, you just have such a calm way of speaking, so partly it might seem that it’s quiet, but on the other hand, it objectively feels like the video about the Scene Manager (a very useful one!) that came out a month ago is a little louder.
I understand that this is my IMHO, but it seems to me that if you speak a little louder, it will be a little better.
BTW, I like the content itself and the way it is presented, do more!
@phoenixweiss This is really helpful feedback. I appreciate your bringing it up! 🙏 I’m still learning something new every day about editing videos and CZcams in general so every bit of feedback makes a big difference. Better every day, right? Thank you for watching and sharing your thoughts! ❤️🤜🤛
cave person 💀
🙈