Godot Debugging Techniques EVERY Dev Should Know

Sdílet
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

Komentáře • 135

  • @BenHunterRolfe
    @BenHunterRolfe Před 2 měsíci +9

    Great tips! I worry that some viewers might not realise that "always on top" affects the behaviour of their final game, though.

    • @baconandgames
      @baconandgames  Před 2 měsíci +1

      Oh really? I honestly thought that was just an editor setting. 😳 Thank you for letting me know.

  • @AMTunLimited
    @AMTunLimited Před 4 měsíci +67

    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

    • @baconandgames
      @baconandgames  Před 4 měsíci +7

      You and me both, but it’s never too late to add to your bag of tricks (or mine)! 🤜🤛

    • @whannabi
      @whannabi Před 4 měsíci +3

      print("It's working!")

    • @baconandgames
      @baconandgames  Před 4 měsíci +3

      That would have been a much shorter video 🤣

    • @BinaryBolias
      @BinaryBolias Před 3 měsíci

      ​@@whannabi
      if not found_errors:
      get_tree().quit(ExitCodes.ERROR_NOT_FOUND)

  • @glorytoarstotzka330
    @glorytoarstotzka330 Před 4 měsíci +25

    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)

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      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!!!

  • @CraftedQuests
    @CraftedQuests Před 4 měsíci +8

    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!

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      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 👋

  • @OctagonalSquare
    @OctagonalSquare Před 4 měsíci +4

    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

    • @baconandgames
      @baconandgames  Před 4 měsíci

      Oooh, that’s a great tip! Thanks for sharing that ❤️

  • @mission-toast
    @mission-toast Před 4 měsíci +1

    Very useful. Thanks for putting this together!

  • @parmeshwarrathod105
    @parmeshwarrathod105 Před 4 měsíci +2

    Man this was good info, you have saved of time i would have spent knowing debugging in godot editor. thanks mate, subscried.

    • @baconandgames
      @baconandgames  Před 4 měsíci

      Thank you, my friend! Looking forward to seeing what you’re working on!

  • @3XC4L1B3R
    @3XC4L1B3R Před 3 měsíci +1

    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.

    • @baconandgames
      @baconandgames  Před 3 měsíci

      Haha. Programming is definitely a humbling experience. I love that you’re having some fun with it.

  • @TheUlf
    @TheUlf Před 4 měsíci +3

    This is so incredibly helpful, thank you!

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      You are so incredibly welcome. Thank you ❤️

  • @nahruz.w3044
    @nahruz.w3044 Před 4 měsíci +1

    I NEED THIS! Thank you for uploading this video

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      🥹 Thank you 🙏 that’s really nice to hear. I’m glad you doing it helpful.

  • @GreenLightDev
    @GreenLightDev Před 4 měsíci +3

    Exactly what I needed--thank you! 🙏

  • @cyborganic
    @cyborganic Před 3 měsíci

    Very helpful video! Thank you!

  • @danielg9446
    @danielg9446 Před 4 měsíci

    It was super informative, ty very much man!!

  • @Peter-wl5xm
    @Peter-wl5xm Před 4 měsíci

    Thanks for all the options!

  • @gimpycoder8548
    @gimpycoder8548 Před 4 měsíci +2

    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.

  • @Gwizz1027
    @Gwizz1027 Před 4 měsíci +2

    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!

    • @baconandgames
      @baconandgames  Před 4 měsíci

      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 🤜🤛

  • @pennyloafers
    @pennyloafers Před 4 měsíci +1

    You should post this in the Godot forums, I think people would have less questions if they understand basic debugging techniques.

    • @baconandgames
      @baconandgames  Před 4 měsíci

      That’s a great idea. I honestly hadn’t considered that 🤦‍♂️🤣 Thank you!

    • @baconandgames
      @baconandgames  Před 3 měsíci

      Great suggestion and done!
      forum.godotengine.org/t/using-the-godot-debugger/49576

  • @LeGAT45
    @LeGAT45 Před 3 měsíci

    Extremely helpful!!

    • @baconandgames
      @baconandgames  Před 3 měsíci

      Thanks for watching! I appreciate you 🙏

  • @darenn-keller
    @darenn-keller Před 4 měsíci

    Really cool video, those auto remote scene switch and always on top parameters are definitely gonna make my life easier. Thanks!

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      🥹 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.

    • @darenn-keller
      @darenn-keller Před 4 měsíci

      @@baconandgames Oh alright I'll be careful then, thanks for the heads up mate!

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      @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!

  • @CaioMGA
    @CaioMGA Před 4 měsíci

    great video. Thanks for uploading

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      Thanks for watching! 🙏 Plenty more coming.

  • @felipefacundes1
    @felipefacundes1 Před 3 měsíci

    Cool !!! Very save !!!

  • @longuemire748
    @longuemire748 Před 2 měsíci

    Thank you for this video.

    • @baconandgames
      @baconandgames  Před 2 měsíci +1

      It’s my pleasure! Thank you for watching 🙏❤️

  • @laoAnGame
    @laoAnGame Před 20 dny

    Thank you. I'm learning Godot!

  • @DEATHTRUTH
    @DEATHTRUTH Před měsícem

    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.

    • @baconandgames
      @baconandgames  Před měsícem

      Oh interesting! Thanks for the tip 🤜🤛

  • @corpsinhere
    @corpsinhere Před 4 měsíci +1

    Quality content: subscribed :)!

  • @VixenteEs
    @VixenteEs Před 4 měsíci

    Nice work. Please keep it up! :)

  • @teahands
    @teahands Před 4 měsíci +1

    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!

    • @baconandgames
      @baconandgames  Před 4 měsíci +2

      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 🙏

  • @Starkandco
    @Starkandco Před 4 měsíci

    Debug window to call whatever stuff helps you test is really useful too. I like to have separate windows than my main application too

    • @baconandgames
      @baconandgames  Před 4 měsíci

      Can you provide more info on this? I’m not sure I fully understand but I’d love to know more 🙏

  • @ekagaurangadas
    @ekagaurangadas Před 4 měsíci +1

    I subscribed when you said "cave person", keep up the good work 😂

    • @baconandgames
      @baconandgames  Před 4 měsíci

      And my parents told me being a smartass would get me in trouble. 🤣 Thanks! 🙏

  • @duolc_7
    @duolc_7 Před 4 měsíci

    Nice tips 👌

  • @alectrem
    @alectrem Před 4 měsíci

    Thank you!

  • @micmacha
    @micmacha Před 4 měsíci +3

    I had no idea about "Always on Top" and "Automatically Switch to Remote". Thank you!

    • @baconandgames
      @baconandgames  Před 4 měsíci

      You’re welcome! Those are game changers for me. It’s wild how many settings there are like that to turn on or off.

  • @DevilBlackDeath
    @DevilBlackDeath Před 4 měsíci +1

    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.

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      That’s super cool! I love this. 👏

    • @DevilBlackDeath
      @DevilBlackDeath Před 4 měsíci

      @@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 :)

    • @baconandgames
      @baconandgames  Před 4 měsíci +2

      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 🤜🤛

    • @DevilBlackDeath
      @DevilBlackDeath Před 4 měsíci

      @@baconandgames So true ! Well thanks for the video and the tips as well and I'll definitely keep an eye out ;)

    • @baconandgames
      @baconandgames  Před 4 měsíci

      🥹🙏

  • @killercrazy21c
    @killercrazy21c Před 4 měsíci

    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.

  • @anonimowelwiatko4455
    @anonimowelwiatko4455 Před 4 měsíci

    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).

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      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!

  • @ryanze26
    @ryanze26 Před 4 měsíci

    thank you!

  • @texcolorado9550
    @texcolorado9550 Před 4 měsíci

    thanks a lot :)

  • @darthnegativehunter8659
    @darthnegativehunter8659 Před 4 měsíci

    very helpful.

  • @Afreshio
    @Afreshio Před 3 měsíci +1

    you gained a subscriber!

  • @AkaiKnight
    @AkaiKnight Před 21 dnem

    *sees "Always On Top option*
    oh my goooooooooooood

    • @baconandgames
      @baconandgames  Před 21 dnem

      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.

  • @luisces
    @luisces Před 4 měsíci

    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.

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      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. 💪

  • @noiJadisCailleach
    @noiJadisCailleach Před 4 měsíci +1

    10 years of software engineering. And i finally learned what that damned red dot that's present in a lot of IDE does! SMH.

    • @baconandgames
      @baconandgames  Před 4 měsíci

      🤣 Well… you still learned it sooner than I did. Thanks for watching 🙏

  • @TheBugB
    @TheBugB Před 4 měsíci +1

    Oh yeah I really love cave person debugging cause I’m from 1500 BCE

  • @noiJadisCailleach
    @noiJadisCailleach Před 4 měsíci

    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!

    • @baconandgames
      @baconandgames  Před 4 měsíci

      This is super helpful, thank you! I will look more closely at volume for this week’s video. 🙏

  • @BinaryBolias
    @BinaryBolias Před 3 měsíci

    *Good:* _Debugging technique explanation & demonstration._
    *Bad:* _Using _*_string_*_ instead of _*_enum_*_ for those "gateway" export variables._ 😱😱😱

    • @baconandgames
      @baconandgames  Před 3 měsíci +1

      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.

    • @baconandgames
      @baconandgames  Před 3 měsíci +1

      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 😉

  • @alicecubensis1221
    @alicecubensis1221 Před 4 dny

    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

    • @baconandgames
      @baconandgames  Před 4 dny +1

      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

    • @alicecubensis1221
      @alicecubensis1221 Před 3 dny

      @@baconandgames wow thank you!! and thanks for all the great tutorials

  • @shoggoth
    @shoggoth Před 4 měsíci

    How are you defining them globals in the node? Any chance I could take a look at the source for that bit?

    • @baconandgames
      @baconandgames  Před 4 měsíci

      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

    • @shoggoth
      @shoggoth Před 4 měsíci

      @@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!

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      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!

    • @shoggoth
      @shoggoth Před 4 měsíci

      I rewatched the bit about the remote scene tree, I understand now. Thanks a lot for your help!@@baconandgames

  • @kishirisu1268
    @kishirisu1268 Před 4 měsíci

    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

    • @baconandgames
      @baconandgames  Před 4 měsíci

      I saw whatever catches the bugs is fine by me 🐛🧲 😬

  • @trepals
    @trepals Před 3 měsíci +2

    Why is CZcams attacking me for no reason with this video

    • @baconandgames
      @baconandgames  Před 3 měsíci +2

      I paid them a LOT of money to target you specifically . So you better watch it, for my sake. Please. I’m begging you. 😅

  • @akaitsuki6466
    @akaitsuki6466 Před 23 dny

    What exactly does having the remote scene tree activated do? The only thing I get is that the program freezes when I run it

    • @baconandgames
      @baconandgames  Před 23 dny

      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.

    • @akaitsuki6466
      @akaitsuki6466 Před 22 dny

      @@baconandgames It is a 3D game with a procedural dungeon, I suppose that being so big it is heavier

    • @baconandgames
      @baconandgames  Před 22 dny

      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

  • @lizardrain
    @lizardrain Před 4 měsíci

    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.

    • @baconandgames
      @baconandgames  Před 4 měsíci

      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!

  • @ShiloBuff
    @ShiloBuff Před 4 měsíci

    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.

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      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 🤜🤛

    • @kishirisu1268
      @kishirisu1268 Před 4 měsíci +1

      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.

    • @baconandgames
      @baconandgames  Před 4 měsíci +1

      @kishirisu1268 took me way longer to do anything but print. 🤜🤛❤️

  • @1gengabe
    @1gengabe Před 4 měsíci +1

    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

  • @phoenixweiss
    @phoenixweiss Před 4 měsíci

    Thanks a lot!
    P.S. the recording is very quiet, it’s hard to hear

    • @baconandgames
      @baconandgames  Před 4 měsíci

      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?

    • @phoenixweiss
      @phoenixweiss Před 4 měsíci

      @@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!

    • @baconandgames
      @baconandgames  Před 4 měsíci

      @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! ❤️🤜🤛

  • @question_mark
    @question_mark Před 4 měsíci

    cave person 💀