Your first Kotlin class
Let's create a file src/main/kotlin/com/yourcompany/game/Simple.kt
with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
The classes section covers in details what we did here, but for now @RegisterClass
will register the class to Godot. Now we can trigger a build.
1 |
|
Once the build completes, you will be able to use your class in Godot. Simply attach the generated gdj
file (By default, generated in the gdj/
directory at the root of the project. For more details, read user guide) to a node like you would do in GDScript. If you rebuild the project while the editor is open, your classes will be reloaded automatically in Godot and you can use them.
Info
As Kotlin is a compiled language you can only use newly created classes after you have built them, otherwise, Godot will not be able to find them.
Final project structure
The final filesystem project should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|