- Setup the Project with the setup instructions below
- Build the Project
- Frist time :
CTRL + P->task initial-build-extension - In VSCode :
CTRL + P->task build-extension - For use in Development Game & Debugging :
CTRL + P->task build-extension [dev build]
- Frist time :
- Ensure that the bin folder contains
ai_blue.gdextension- If not you can find one in the Godot Docs: https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html#using-the-gdextension-module
- Modify the Agents Folder && AI_Blue_Agent.cpp/.h to fit your project needs
- Write your HTN Domains and World States in C++
- Write your Operators to call functions in GDScript, to perform actual actions in your game
- Build the project when you finalize your C++ code
- Copy the bin folder
game/binto your project - Use your Agent Nodes
- In the included example the Agent Brains are setup as Node3D, that can be found in the search of the add node menu in Godot engine
- Call functions on the Agents inside GDScript
- Get a path to your Agent 3D node, and call the functions you defined for sensors in your Agent-C++
This setup assumes you are using Windows.
- Clone the repo
git clone --recurse-submodules https://github.com/kthecoder/AIBlue.git
- Get the Godot CPP Submodules if you didn't use --recurse-submodules
git submodule update --init --recursive
- Install Python and Scons
- Changes were already made to the .vscode/tasks.json to make pathing easier
- Change
sconstopython -mSConsor else you will bang your head against a wall trying to get the pathing to work on windows
- Change
.vscode.vscode/launch.json- Replace
"program": "C:/Program Files (x86)/Godot_4.2.1/Godot_v4.2.1.exe",with the location of your Godot exe
- Replace
.vscode/c_cpp_properties.json- Replace
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe",with the location fo yourcl.exe - This is for windows only, compiler pathing will differ on mac and linux
- Replace
- C++ Configurations
- Must include new directories inside
c_cpp_properties.json
- Must include new directories inside
- SCONS Configuration
- Must include extra folders in the
SConstruct'ssources; if you desire a different setup
- Must include extra folders in the
CTRL+SHIFT+P then type task build
- For the initial build you can run the vscode task
initial-build-extension.- This compiles both godot-cpp and the extension.
- For all subsequent builds, you only need to run the task
build-extension.
- First ensure you have run the
build-extension [dev build]vs code task command- Command found in the
CTRL + Pmenu, typetask - To use this command you need to also modify your specific Godot paths inside the
.vscode/tasks.jsonfile. - You need to set the path to your godot project folder
- Command found in the
- You can then run the debug in VS Code
- Use :
Run Demo [FROM GAME] - [DEBUG MODE]
- Use :
- When you get errors that are due to FluidHTN
- The errors will show a line in FluidHTN and it will actually be the Fatal Exception in the line of code above that
There are two ways of implementing C++ into Godot.
- Linking (Modules)
- Implement Custom DLL's that are called on Runtime
- Can make small changes and only have to rebuild DLL's but for each platform
- Create a GDExtension Library
- Add GDExtension Library to the GDScript's NativeScripts export option in the inspector panel
- If done correctly there should be a node called "AIBlueAgent"
- Attaching this to the scene connects the GDExtension to your game
- Documentation : https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html
- Tutorial : https://youtu.be/kn8H2nlx3xY?si=Fyp35O7tR6weiRNk
- Integration
- Implement the C++ code into the engine
- Basically you rebuild the engine and include your C++ code
- No platform specific DLL's needed
- Have to build the engine every time you make a change to the C++ code
- Tutorial : https://www.youtube.com/watch?v=81uoyvvSG2A&list=PLZ2NyOcFnfQOko5ZysZeGkH3bfw2UtbOK&index=8
- Implement the C++ code into the engine
Note : You could develop your extension using GDExtension and then when you are ready to ship your game, you could build an Integration into the actual engine to avoid needing platform specific binaries.