-
Notifications
You must be signed in to change notification settings - Fork 9
01.Setting up the project
At first, please work according to the contents of Godot Docs - Setting up the project.
We will start the project in the following state:
.
├── art
│ ├── enemyFlyingAlt_1.png
│ ├── enemyFlyingAlt_2.png
│ ├── enemySwimming_1.png
│ ├── enemySwimming_2.png
│ ├── enemyWalking_1.png
│ ├── enemyWalking_2.png
│ ├── gameover.wav
│ ├── House In a Forest Loop.ogg
│ ├── playerGrey_up1.png
│ ├── playerGrey_up2.png
│ ├── playerGrey_walk1.png
│ └── playerGrey_walk2.png
├── fonts
│ ├── FONTLOG.txt
│ ├── LICENSE.txt
│ └── Xolonium-Regular.ttf
├── icon.svg
├── icon.svg.import
└── project.godot
Development with gdext-nim depends on the following software Please make sure that you meet the requirements.
Software | Confirmation |
---|---|
Godot >= 4.4 |
godot --version : 4.4.X.stable.YYY
|
Nim >= 2.0 | nim -v |
gdext >= 0.10 | nimble list -i | grep gdext |
Let's define a new extension by executing the following command in your project root (the folder that project.godot is placed):
gdextwiz new-extension nimmain
That will create a nim/
folder as follows:
.
├── nim
│ └── nimmain
│ ├── bootstrap.nim
│ ├── config.nims
│ └── src
│ └── classes
│ └── gdmyclass.nim
≈
Let's quickly build the extension and make sure gdext works.
gdextwiz build
The gdextwiz build
command builds the specified Nim extension. If unspecified, all buildable extensions are targeted.
Did you succeed in your build? If so, you would like to add some nodes to your scene. Conveniently, the gdextwiz new-extension
command defines a MyClass class as a sample. Let's add this one.
Note
For those familiar with GDNative (pre-Godot 3 expansion system):
As you can see, classes defined using GDExtension are registered in the engine's class database as entirely new classes, not scripts.
It is a sad decision, but MyClass is no longer needed, so let's delete it. Delete the file nim/nimmain/src/classes/gdmyclass.nim and remove the import statement from nim/nimmain/src/bootstrap.nim.
# nim/nimmain/src/bootstrap.nim
import gdext
- import classes/gdMyClass
GDExtensionEntryPoint
bootstrap.nim is the entry point for the Nim extension. By importing the required classes from this file, they will be recognized by the engine.
Now let's rebuild the extension and focus the editor, and you will see that MyClass can no longer be added to the scene. As you can see, gdext-nim supports hot reloading. You can proceed with development without restarting the editor.
Nevertheless, the integration between gdext-nim and Godot Editor is not perfect. If you encounter a puzzling error, try restarting the editor once.