How To Use and Debug GD Extension With Godot 4.1! Advanced Godot!

Поділитися
Вставка
  • Опубліковано 29 чер 2024
  • Subscribe and learn more from me about Game Development and Programming!
    In this video, we'll explore the process of setting up and utilizing C++ with GDExtension for your Godot projects. Learn how integrating C++ can enhance your game development workflow. Whether you're an experienced developer or just starting out, this video will offer step-by-step guidance to effortlessly set up C++ in Godot using GDExtension. Elevate your game's performance and robustness with the combination of C++ and Godot 4.1. Experience the power of merging the best of both domains!
    RESOURCES
    Python: www.python.org/
    CPP Extension: github.com/godotengine/godot-cpp
    SConstruct file:
    #!/usr/bin/env python
    import os
    import sys
    env = SConscript("godot-cpp/SConstruct")
    For reference:
    - CCFLAGS are compilation flags shared between C and C++
    - CFLAGS are for C-specific compilation flags
    - CXXFLAGS are for C++-specific compilation flags
    - CPPFLAGS are for pre-processor flags
    - CPPDEFINES are for pre-processor defines
    - LINKFLAGS are for linking flags
    tweak this if you want to use different folders, or more folders, to store your source code in.
    env.Append(CPPPATH=["src/"])
    sources = Glob("src/*.cpp")
    if env["platform"] == "macos":
    library = env.SharedLibrary(
    "demoproject/bin/HelloWorld.{}.{}.framework/helloWorld.{}.{}".format(
    env["platform"], env["target"], env["platform"], env["target"]
    ),
    source=sources,
    )
    else:
    library = env.SharedLibrary(
    "demoproject/bin/HelloWorld{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
    source=sources,
    )
    Default(library)
    Launch.json:
    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: go.microsoft.com/fwlink/?link...
    "version": "0.2.0",
    "configurations": [
    {
    "type": "lldb",
    "request": "launch",
    "preLaunchTask": "build",
    "name": "Debug",
    "program": "C:\\Users\\FinePointCGI\\Downloads\\Godot_v4.1.1-stable_mono_win64\\Godot_v4.1.1-stable_mono_win64\\Godot_v4.1.1-stable_mono_win64.exe",
    "args": ["--path", "C:\\Users\\FinePointCGI\\Documents\\Godot CPP Tutorial\\demoproject"],
    "cwd": "${workspaceFolder}"
    }
    ]
    }
    Tasks.json:
    {
    // See go.microsoft.com/fwlink/?Link...
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
    {
    "label": "build",
    "type": "shell",
    "command": "scons -j12 target=template_debug debug_symbols=yes"
    }
    ]
    }
    BE MY FRIEND:
    🐦Add me on Twitter: / finepointcgi
    Check out my Website: finepointcgi.io/
    Where to suggestion Things: github.com/finepointcgi/Finep...
    You can support me on Patreon: / finepointcgi
    Hang Out with the Guys on Discord: / discord
    TIMESTAMPS
    00:00:00 - Start
    00:00:57 - Installing Pyton
    00:02:57 - Installing Scons
    00:03:55 - Getting the Godot C++ Project
    00:06:14 - Compiling the Godot C++ Project
    00:08:43 - Oh Boy Its Compiled!
    00:10:48 - Setting Up VS Code for C++
    00:11:20 - Creating Our First Header File
    00:16:38 - Creating Our C++ File
    00:19:20 - Building Out Our Constructor
    00:20:13 - Registar Our Plugin With Godots Subsystem
    00:24:00 - Explaning Initalization Levels
    00:25:58 - Using Extern C to Initalize Our Plugin
    00:30:38 - How To Build Your Plugin
    00:33:39 - Creating Our Godot Project
    00:34:29 - Creating a GD Extension File
    00:38:30 - Welp Something Blew Up
    00:39:01 - Showing Off Our Node
    00:40:53 - How To Stop Your Plugin Running in the Background When Not Playing Th Egame
    00:42:32 - Why Godot Needs To Be Closed
    00:43:46 - How To Move Stuff Around!
    00:46:38 - Exposing Our Variables to the Godot Inspector
    00:52:07 - Setting Up Our Player Actions
    00:52:44 - Creating Signals and Functions for GD Script
    00:55:41 - How To Use Our Node With GD Script
    00:58:06 - How Can You Debug in VS Code?
    01:04:41 - Outro and Recap
    MUSIC
    Music provided by TheRelaxedMovement.
    Check it out here: / therelaxedm...​
    HASHTAGS:
    #C++ #Godot4 #GDExtension
    ABOUT MY CHANNEL:
    I've been a software developer for over 9 years. I've worked in the game industry for 3 of those years. This channel is used for news on the gaming\programming industry and for tutorials for game\programming development.
    How To Use and Debug GD Extension With Godot 4.1! Advanced Godot 4!

КОМЕНТАРІ • 88

  • @GabrielVeda
    @GabrielVeda 5 місяців тому +17

    Please note carefully the title people. This is for *4.1*. Don't be me and waste a day attempting to follow this on 4.2. Instead, go to the official godot gdextension c++ example page and work directly off the example there. You will be up and running in 1/4 of the time it takes to watch this video. If you see something like: "Can't resolve symbol hello_world_init, error: "Error 127: The specified procedure could not be found." then this warning particularly applies to you.

    • @FinePointCGI
      @FinePointCGI  5 місяців тому +2

      I'm going to have to update this tutorial if things have changed that much..

    • @GabrielVeda
      @GabrielVeda 5 місяців тому

      @@FinePointCGI I think this step might have been the missing ingredient I needed: godot.exe --dump-extension-api then scons platform= custom_api_file=

    • @purplepixeleater
      @purplepixeleater 2 місяці тому

      @@GabrielVeda Were you using a custom build? That seems a bit strange to need to dump the api unless there were build changes.

    • @Pabloparsil
      @Pabloparsil Місяць тому

      It does work now in 4.2, but you have to take care to compile the 4.2 branch, otherwise it won't work

  • @Syl4r93
    @Syl4r93 9 місяців тому +19

    This is just what I was looking for, thanks a lot!!
    Btw, at 47:20 the "const" after the "get_speed()" function definition is there to guarantee that the method won't modify any member data of the object. In fact, if for example you try to do something like "speed = 0.0;" inside that method, you will get a compiler error because the method is not allowed to modify the object. This makes it possible for the method to be called on const instances of the class, so in this case if you had somewhere something like "const HelloWorld my_object;" it would be safe to call "my_object.get_speed();" because the compiler makes sure that the function is not modifying the object.

  • @sawomirgrabowski1722
    @sawomirgrabowski1722 7 місяців тому +15

    26:45 extern C is required to prevent mangling. Mangling is finding unique name for function and renaming to it. In C++ we have function overloading allowing the creation of same named function but with different type of parameters. In C this is not allowed so mangling do not happen. Then godot engine code can find function by name and call it.
    That is the difference between shared library and plug-in (module) library. First one is linked during compilation, but second one is not linked, it is opened during runtime, eg. in Linux by system function DLL open

  • @pytebyte
    @pytebyte 5 місяців тому

    Best video I found so far about this topic. Very helpful. Thank you :)

  • @remifasollasido6933
    @remifasollasido6933 8 місяців тому +9

    Thank you very much this is exactly what I needed.
    One small but very useful new feature in Godot 4.2 is that you no longer need to close and reopen godot when you compile. As long as you don't do something esoteric with memory management it works as intended.

    • @QIZI94
      @QIZI94 8 місяців тому +2

      could you point me what should I look for, to get this information, if I wanna see that this is actually a planned feature of Godot 4.2 ?

  • @zurreality
    @zurreality 4 місяці тому +1

    As always and I think I am already repeating myself for the 4th time, but big thanks :D! I got myself into Godot and loving it very much... and I think i wouldn't be this far without Your help :D! You are rocking hard x)

    • @FinePointCGI
      @FinePointCGI  4 місяці тому +1

      Hey I'm glad your getting something out of my insane ramblings!

  • @ivailoburov1295
    @ivailoburov1295 8 місяців тому +7

    Thanks for your work, effort and patience.
    All this work of initialization, registering, binding and creating of scons and gdext description files should be automated by some tool or plugin. We have C++ mainly in both .h and .cpp files. Everything else is a waste of time outside of the functionality being created, which is boring.
    Although I prefer C++, this is holding me back from using it for now.

  • @runescape2738
    @runescape2738 6 місяців тому +1

    I almost never like videos or subscribe (last time i subscribed to someone was 2+ years ago) but man you have the best tutorials out there. Thanks a lot and keep them coming!

    • @FinePointCGI
      @FinePointCGI  6 місяців тому

      Hey thanks! Im glad you like them! Let me know if you have anything you want covered im always up for a challange (though not too hard!)

  • @Carkoon
    @Carkoon Місяць тому +1

    Thanks! Finally got it to work. In my case everything seemed to work also with Godot 4.2.

  • @risajadewasurendre8298
    @risajadewasurendre8298 9 місяців тому

    awesome as always

  • @InfernalWAVE
    @InfernalWAVE 3 місяці тому

    i cant thank you enough. i have learned so much from you

  • @RobertCT86
    @RobertCT86 7 місяців тому

    thanks for the tutorial, i read the documentation and got lost and the ADHD was kicking so that didnt help, watch a different tutorial that skipped the gdextension part so i was lost as of why GODOT never used any of my code, finally watching this tutorial i finally have a compiled DLL that works.

  • @Jova
    @Jova 4 місяці тому +1

    in 4.2+ (i think), if you add "reloadable = true" in the .gdextension file under [configuration], you can recompile without reloading godot

  • @leonardo6631
    @leonardo6631 8 місяців тому +4

    Amazing tutorial!!! BTW 42:42 you don't need to close Godot to compile the extension, you just need to remove the extension from the project!
    move the file ".gdextension" from your project, click on the Godot window, compile the extension, and then move it back!

    • @FinePointCGI
      @FinePointCGI  8 місяців тому

      Interesting I'll definitely have to try that!

    • @natgazer
      @natgazer 8 місяців тому +2

      Godot 4.2 will have this issue solved. You won't need to close the engine to update GDExtension no more!

  • @Ah2o5b
    @Ah2o5b 9 місяців тому

    Amazing video as always can you continue with programming languages and make a video about python with the new gdextension.

  • @owenlloyd2528
    @owenlloyd2528 9 місяців тому

    Thank you. I have been looking for ways to include a .dll in godot, the dll was created way back using a basic language (so no .h, etc). I cannot work out how to do this so I guess I am going to have to learn C and remake the thing as a static .obj/so. This was helpful (if a bit daunting, lol)

  • @dzartxstudio
    @dzartxstudio 9 місяців тому

    Ohhhhhh🎉🎉🎉 what a legend ❤❤

  • @williamgodwin5582
    @williamgodwin5582 8 місяців тому +4

    WE NEED MORE С++!!! )))

  • @Tarikaydin16
    @Tarikaydin16 6 місяців тому +5

    Godot 4.2 is out! For apply fast reloading, just paste "reloadable = true" under the configuration section!

    • @FinePointCGI
      @FinePointCGI  6 місяців тому

      I love that they fixed that! Now we just need c# GD extension support.. regenerating the glue after import is pain!

    • @pxolqopt3597
      @pxolqopt3597 5 місяців тому

      It causes godot to crash me for when replacing the library file

  • @yanchobeats
    @yanchobeats 9 місяців тому +5

    Awesome work as always! Can you do a tutorial on how to add our game on Steam using GDScript and how to use Steam's different things like lobbies, servers, bans, voice chat, etc? It will be an awesome tutorial!

    • @SuperFranzs
      @SuperFranzs 6 місяців тому +1

      GodotSteam is a great library for this. The documentation on their website is great as well.

    • @FinePointCGI
      @FinePointCGI  6 місяців тому +2

      I just released a tutorial on this this past Monday!

  • @darthnegativehunter8659
    @darthnegativehunter8659 4 місяці тому

    as everyone says. exactly what i was looking for :))
    i have a cmake setup though. i was trying to find out how to add debugging for it.

    • @FinePointCGI
      @FinePointCGI  4 місяці тому

      If you don't mind I was actually looking into doing a CMake setup and I would love to know how to do it.. it's something I wanted to make an additional tutorial on

  • @Theo_drawi
    @Theo_drawi 9 місяців тому

    Thank you:)

  • @arielgimenez_95
    @arielgimenez_95 7 місяців тому

    Thanks, I was able to make it work in Linux. What I would like is to be able to change the icon for GDextension, because I don't like that each GDextension node is gray like a node, it confuses me a little.. Greetings!

  • @terrasil7834
    @terrasil7834 9 місяців тому

    Imo reloadable = true in configuration in .gdextension should allow to dynamic reload .dll with editor opened

  • @michaeljburt
    @michaeljburt 3 місяці тому

    Has anyone else figured out how to get debugging to work with VSCode/LLDB in Godot v4.2.1? There's a couple of other reddit posts that discuss this method as well, and it seems broken in 4.2

  • @Reddune92
    @Reddune92 Місяць тому

    could you explain the Custom resource format loaders ?
    I tried to implement the example but i get a bunch of errors. For examile the RESOURCE_LOADER_JSON_H also has the same error you have at 13:30 with the GDCLASS but it does not implement bind_methods (because of course it does not need them )
    then another question why do they not use the godot-cpp but core/io? is it to rebuild the engine? And why is the folder structure so different from the Godot-cpp

  • @justiof5569
    @justiof5569 5 місяців тому +1

    Awesome tutorial! I finally managed to create a node and use it in Godot.
    The only problem I'm having is debugging: the program does not break at the breakpoints. I redid everything from the start, but it still doesn't work. Did anyone else have the same problem?

    • @michaeljburt
      @michaeljburt 3 місяці тому +1

      I'm getting the exact same issue.. so I will stay posted to see if anyone else figures it out. My breakpoints are also not triggering in 4.2.1. Otherwise, everything else works.

    • @heeho5495
      @heeho5495 20 днів тому

      @@michaeljburt still stuck on this as well! anyone found a solution yet?

  • @icespeaker81
    @icespeaker81 8 місяців тому

    You work with shaders yet? How do you feel about them?

  • @kushs-labs
    @kushs-labs 8 місяців тому +1

    Hi, can you redirect to how to setup Visual Studio 2022 for GDExtension C++. Have used Visual Studio for a long time now and didn't find VSCode to be for me. Please and Thanks :)

  • @multis3484
    @multis3484 Місяць тому

    42:44 I think this limitation is gone, as I didn't receive any error on my windows machine while godot was running.
    Edit: The problem now is that godot will not load automatically, you need to manually restart the project, you can do this on 'project->Reload Current Project' tho...

  • @onnjil855
    @onnjil855 2 місяці тому

    How to create GDExtensions component in this version Godot_v4.3-dev5

  • @Rogueixpresents
    @Rogueixpresents 9 місяців тому

    hello sir, can I ask a big favor? I know this is a lot but could you take into consideration for next upcoming Godot videos? Such as more on the programming? i am talking about more on the idea of, programming as a 'game developer' i am coming from web dev, and some backend, rest api... but game dev is null pointer for me lol, i wanna learn how to think coding game logic and etc...
    thanks in advance!

  • @Pabloparsil
    @Pabloparsil Місяць тому +1

    In 4.2 they seem to have moved the PROCESS_MODE_DISABLED to inside Node, like so:
    set_process_mode(Node::PROCESS_MODE_DISABLED);
    I wish someone would do a performance comparison between GDScript and C++ btw..

    • @Carkoon
      @Carkoon Місяць тому +1

      Are you sure? I did it like in the video at it seems to work fine. Or are there other issues with it?

    • @Pabloparsil
      @Pabloparsil Місяць тому +1

      @@Carkoon Are you using 4.1 or 4.2? I just followed what the autocomplete told me and it works lol

    • @Carkoon
      @Carkoon Місяць тому +1

      @@Pabloparsil I just tested it and apparently both work? I used 4.2

    • @Pabloparsil
      @Pabloparsil Місяць тому +1

      @@Carkoon oh ok, then maybe they didn't move it at all. Thanks for the info

  • @user-fv8uv2us9r
    @user-fv8uv2us9r 4 місяці тому

    Sorry, just interested: why not "pragma once"?

  • @mayronen9643
    @mayronen9643 7 місяців тому

    I use neovim as my code editor, after following the tutorial I get the error: 'godot_cpp/classes/node2D.hpp' file is not found, how would I fix it?

    • @pxolqopt3597
      @pxolqopt3597 5 місяців тому

      You need a compile_commands.json file in order for clangd (if youre using clangd) to understand how your project is built and provide intellisense based on that. If you build the gdextension with Cmake its easy to ask cmake to automatically make a compile_commands.json, but if you are using Scons you have to google that yourself

  • @Kickin0u0in0the0nut
    @Kickin0u0in0the0nut 7 місяців тому

    Just quick question if I am running a source build, I assume in this case I would compile my source build to static lib instead of cloning godot cpp?

    • @Kickin0u0in0the0nut
      @Kickin0u0in0the0nut 7 місяців тому

      Bit of a follow up, Is there any point to doing gde, I wanted to try it cuss of 4.2 and hot swaping, but I feel like it dose not have any advantage over just using source build and module, I even fill like I am writing 10 times more boiler code, anyone else feel this way? I feel like I am missing somthing cuss I dont understand why people would pick gde over just making a module

    • @FinePointCGI
      @FinePointCGI  7 місяців тому

      @Kickin0u0in0the0nut overall making a GDExtension is easier for you to share with other people. Outside of that there really isn't a huge advantage.

    • @Dirtboy37
      @Dirtboy37 4 місяці тому

      @@Kickin0u0in0the0nut main reason is that you do not need to recompile the engine when you edit your cpp code

  • @superj1e2z6
    @superj1e2z6 9 місяців тому

    I wonder how would C# work when it gets transferred to GDExtension. There's just a bunch of boilerplate for cpp so what happens for C#.

    • @HenryLoenwind
      @HenryLoenwind 9 місяців тому +1

      In that case, you wouldn't be writing the GDExtension yourself, but using a C#-bridge extension. Most (all?) of the language extensions we have so far are made to allow you to create GDExtensions in various languages. That's useful, too, but what the devs mean by bringing in C# as a supported language for writing Node scripts is to have a bridge extension to support C#, not to write the extension *in* C#.

    • @aaaaaaa7836
      @aaaaaaa7836 8 місяців тому

      @@HenryLoenwind Writing directly in C++ would be more performant than using a language bridge?

    • @HenryLoenwind
      @HenryLoenwind 8 місяців тому

      @@aaaaaaa7836Naturally. You'd avoid plenty of code in the bridge, and just executing more code is slower than not executing code.
      In addition, C++ compiles to less code because the runtime adds less extra code on top of what you write. The ideal case would be assembler, as that adds no extra code at all. Then macro assembler, which adds only minimal extra code, then C, whose instructions map relatively closely to CPU instructions, and so on.
      For example, in assembler, a RET generates a single CPU instruction, whereas in a Javascript interpreter written in Java on an x86 JVM running in an X86 emulator on an arm processor, a single "return;" needs several tens of thousands of CPU instructions to be executed.

  • @grif7087
    @grif7087 8 місяців тому

    I've followed I don't know how many tutorial and every time I arrive at the first compilation with scons I get an error. I followed the tutorials and don exactly the same things, yet I don't manage to compile this.
    The worst part in all this, I haven't had time a line of code so I've got no clue what went wrong.

    • @FinePointCGI
      @FinePointCGI  8 місяців тому +1

      What errors are you getting? Did you pull the submodules?

    • @pierreb8972
      @pierreb8972 7 місяців тому

      same here, looks like scons doesn't find the .o files @@FinePointCGI

  • @lehisluguer9300
    @lehisluguer9300 Місяць тому +1

    im using 4.2.2 and not able to debug.. please help..

    • @Reddune92
      @Reddune92 Місяць тому

      I am also using 4.2.2 and debugging works fine. If you want help you need to go into more detail what does not work mean^^ does nothing open? do you get an error message?

  • @goshawk_fly
    @goshawk_fly 7 місяців тому

    What do you think? Can Godot team make C++ integration more simple like C# in Godot mono?

    • @FinePointCGI
      @FinePointCGI  7 місяців тому +1

      In my humble opinion no c++ is always going to be difficult because it's integrating directly with the engine not being used with a translation layer like C#

    • @goshawk_fly
      @goshawk_fly 7 місяців тому

      @@FinePointCGI If I understand in right way, Godot team has plan to add another official supporting languages in the future in GDextention style, but not in Godot Mono Style?

    • @goshawk_fly
      @goshawk_fly 7 місяців тому

      @@FinePointCGI @FinePointCGI What do you think about performans of Stride Game Engine? It has 90% of code at C#. Is there high risk of unexpecting freezing? I like render quality of this engine. Also I guess it'easy to modify it.

  • @Xero_Wolf
    @Xero_Wolf 5 місяців тому

    9:00 I'm getting a ".a" file instead of ".lib" It's this normal? I'm using the Godot 4.2 and used platform = windows when building.

    • @AetherPowered
      @AetherPowered 5 місяців тому +3

      Because you are using mingw and not msvc

    • @Xero_Wolf
      @Xero_Wolf 4 місяці тому

      @@AetherPowered Thank you but how you you ensure it complies using msvc

  • @AndrewRedW
    @AndrewRedW 4 місяці тому

    Instead of #ifendef we can just use #pragma once. You won't have to explain to beginners why you add it, just say its important to add at the beginning of every header file. 😄

  • @cycomkid
    @cycomkid 8 місяців тому

    You were creating some kind of horror game. Is that complete? I cannot see the completed game video demo

  • @Reddune92
    @Reddune92 Місяць тому

    So in Godot 4.2.2 UtilityFunctions::print("Hello"); somehow does not print anything to the terminal. I only get the usual :
    Godot Engine v4.2.2.stable.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
    modules/gltf/register_types.cpp:63 - Der Blend-Dateiimport ist in den Projekteinstellungen aktiviert, aber es wurde kein Blender-Pfad in den Editoreinstellungen festgelegt. Es werden keine Blend-Dateien importiert.
    --- Debug adapter server started ---
    --- GDScript language server started on port 6005 ---
    I Debuged to the location of the print statmenet and it does seem to call it. Anybody got any Ideas?

  • @nathanbanks2354
    @nathanbanks2354 9 місяців тому +1

    I've found the tricky part is trying to debug GD script code on Godot as well as C++ at the same time. On Linux, the easiest way I've found was to start the project using Godot, figure out what its process ID is, and then attach lldb to this process ID. The problem is that Godot is actually executed twice--once for the editor and a second time for the game. However you can run:
    pgrep --full .odot.\*remote-debug
    to find the process ID because the client has the extra parameters "remote-debug" whereas the editor does not. The regex '.odot.*remote-debug' will match either Godot or godot and the '.*' is a wildcard that matches an arbitrary number of characters.

    • @nathanbanks2354
      @nathanbanks2354 9 місяців тому +1

      My launch.json looks something like this (I use it for rust, but it should work for C++ extensions too):
      {
      "version": "0.2.0",
      "configurations": [
      {
      "name": "Attach Rust Debug",
      "type": "lldb",
      "request": "attach",
      "pid": "${input:GodotNotEditingPID}"
      }
      ],
      "inputs": [
      {
      "id": "GodotNotEditingPID",
      "type": "command",
      "command": "shellCommand.execute",
      "args": {
      "command": "pgrep --full .odot.\\*remote-debug",
      "description": "Ignore the editor, select the program we're debugging",
      "useFirstResult": true,
      }
      }
      ],
      }

    • @nathanbanks2354
      @nathanbanks2354 9 місяців тому +1

      After this I can put a break-point in VS Code and a different breakpoint in the GD Script in the Godot editor and they both work. The only problem is that I can only attach the VS Code debugger _after_ running the game from Godot. Usually this doesn't matter, but you could add a delay in GD Script to give you time. There's also a way to execute a shell command to run VS Code and tell it to connect the debugger as the game starts up, but I found this awkward and can't remember how I did it.