You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/doc/getting-started/your-first-class.md
+3-5
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,19 @@ Let's create a file `src/main/kotlin/com/yourcompany/game/Simple.kt` with the fo
4
4
packagecom.yourcompany.game
5
5
6
6
importgodot.Node3D
7
-
importgodot.annotation.RegisterClass
8
-
importgodot.annotation.RegisterFunction
7
+
importgodot.annotation.GodotScript
9
8
importgodot.global.GD
10
9
11
-
@RegisterClass
10
+
@GodotScript
12
11
classSimple: Node3D() {
13
12
14
-
@RegisterFunction
15
13
overridefun_ready() {
16
14
GD.print("Hello world!")
17
15
}
18
16
}
19
17
```
20
18
21
-
The [classes](../user-guide/classes.md) section covers in details what we did here, but for now `@RegisterClass` will register the class to Godot. Now we can trigger a build.
19
+
The [classes](../user-guide/classes.md) section covers in details what we did here, but for now `@GodotScript` will register the class to Godot. Now we can trigger a build.
Copy file name to clipboardExpand all lines: docs/src/doc/index.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Also consider the [API Differences](user-guide/api-differences.md) section for g
26
26
and limitations which will not be or cannot be adressed in the near forseable future or ever.
27
27
28
28
- Each registered constructor must have a unique number of arguments, constructor overloading is not yet supported.
29
-
- No tool mode (you can set it already in the `@RegisterClass` annotation but it has no effect yet).
29
+
- No tool mode (you can already use the `@Tool` annotation, but it has no effect yet).
30
30
- No addon support, you cannot use Godot Kotlin/JVM to write plugins and addons yet (you can however [write libraries](develop-libraries/introduction.md) with godot specific code).
31
31
- Web is currently not supported. See [Supported platforms](#supported-platforms) to see what platforms we currently support
Copy file name to clipboardExpand all lines: docs/src/doc/user-guide/advanced/abstract-classes.md
+6-11
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ You can define a abstract class and register it's members the same way as you do
7
7
Under the hood, we only register your normal classes, and let them register all members your abstract class defines.
8
8
9
9
!!! info
10
-
For this reason, the `@RegisterClass` annotation is optional for abstract classes.
10
+
For this reason, the `@GodotScript` annotation is optional for abstract classes.
11
11
12
12
!!! warning
13
13
As in Kotlin, you cannot instantiate abstract classes directly from any other scripting language like GDScript! In fact, godot does not even know (or care) that your abstract class exists.
@@ -17,37 +17,32 @@ Under the hood, we only register your normal classes, and let them register all
17
17
Abstract class definition:
18
18
19
19
```kotlin
20
-
//register class annotation is optional for abstract classes
20
+
//@GodotScript annotation is optional for abstract classes
// registered automatically as the abstract class already defines the annotation
46
44
overridefunabstractFunction() {
47
45
// some implementation
48
46
}
49
47
}
50
48
```
51
-
52
-
!!! warning "Registration of overridden members"
53
-
As you can see in the example; you need to explicitly register any member in the child class which you override from the abstract parent class. Otherwise they will not be registered and thus are not known to godot.
Copy file name to clipboardExpand all lines: docs/src/doc/user-guide/classes.md
+12-14
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
-
To expose a class written in Kotlin it needs to extend `godot.Object` (or any of its subtype) and must be annotated with `@RegisterClass`.
1
+
To expose a class written in Kotlin it needs to extend `godot.Object` (or any of its subtype) and must be annotated with `@GodotScript`.
2
2
3
3
```kt
4
-
@RegisterClass
4
+
@GodotScript
5
5
classRotatingCube: Node3D() {
6
6
// ...
7
7
}
@@ -13,7 +13,7 @@ Each registered classes will generate its own .gdj files. For more information,
13
13
14
14
Classes need to be registered with a unique name as Godot does not support namespaces (or packages in this case) for script classes.
15
15
16
-
By default, we register your classes with the name you give them. While beign a simple approach and enough in most cases,
16
+
By default, we register your classes with the name you give them. While being a simple approach and enough in most cases,
17
17
this can lead to naming conflicts if you have classes in different packages with the same name. For example:
18
18
19
19
-`com.package.a.MyClass`
@@ -25,7 +25,7 @@ So you are responsible for making sure that classes have a unique name.
25
25
We do however provide you with some assistance:
26
26
27
27
- We have compile time checks in place which should let the *build fail* if classes would end up having the same name.
28
-
- The `@RegisterClass` annotation lets you define a custom registration name: `@RegisterClass("CustomRegistrationName")`.
28
+
- The `@GodotScript` annotation lets you define a custom registration name: `@GodotScript("CustomRegistrationName")`.
29
29
- Register the class names with the fully qualified name: `com.mygame.MyClass` will be registered as: `com_mygame_MyClass`. This can be configured with:
30
30
```kotlin
31
31
godot {
@@ -93,7 +93,7 @@ If you want to be notified when initialization and destruction of your class' in
93
93
andoverride the `_onDestroy` function respectively.
94
94
95
95
```kt
96
-
@RegisterClass
96
+
@GodotScript
97
97
classRotatingCube: Node3D() {
98
98
init {
99
99
println("Initializing RotatingCube!")
@@ -110,7 +110,6 @@ class RotatingCube: Node3D() {
110
110
Checking if an object is an instance of a particular type can be done via the `is` operator.
111
111
112
112
```kt
113
-
@RegisterFunction
114
113
overridefun_ready() {
115
114
val parent = getParent()
116
115
if (parent isCollisionShape) {
@@ -128,7 +127,6 @@ This also works for any type you define.
128
127
If you are sure that an object is always an instance of some type, then you can take advantage of Kotlin's [contracts](https://kotlinlang.org/docs/reference/whatsnew13.html#contracts) feature. This allows you to avoid having nested `if`s.
129
128
130
129
```kt
131
-
@RegisterFunction
132
130
override fun _ready() {
133
131
val parent = getParent()
134
132
require(parent is CollisionShape)
@@ -140,15 +138,15 @@ This also works for any type you define.
140
138
## Constructors
141
139
142
140
Godot requires you to have a default constructor on your classes.
143
-
You can define additional constructors but you have to register them by annothing them with `@RegisterConstructor`.
141
+
You can define additional constructors, but you have to register them by annotating them with `@GodotMember`.
144
142
Default constructors, on the other hand, are always registered automatically.
145
143
146
144
Constructors can also have **a maximum of 8 arguments** and must have a unique argument count as constructor overloading is not yet supported.
147
145
This limitation is only for registered constructors.
148
146
149
147
### Instantiate Kotlin script classes in GDScript
150
148
151
-
From GDScript it is possible to create an instance of a Kotlin class using the default constructor:
149
+
From GDScript, it is possible to create an instance of a Kotlin class using the default constructor:
152
150
153
151
```kt
154
152
var instance :=YourKotlinClass.new()
@@ -161,24 +159,24 @@ var instance := load("res://gdj/YourClass.gdj").new(oneArg, anotherArg)
161
159
```
162
160
163
161
!!! info
164
-
The limitation of max 16 arguments for constructors is arbitrary. We decided to introduce this limitation to prevent performance bottlenecks for creating objects as each argument passed to a constructor needs to be unpacked by the binding. The more arguments, the more unpacking is needed which means more overhead.
162
+
The limitation of max 8 arguments for constructors is arbitrary. We decided to introduce this limitation to prevent performance bottlenecks for creating objects as each argument passed to a constructor needs to be unpacked by the binding. The more arguments, the more unpacking is needed which means more overhead.
165
163
166
164
167
165
## Customization
168
166
169
167
You can customize to some extent how your class should be registered in Godot.
170
168
171
-
The `@RegisterClass` annotation takes only one argument:
169
+
The `@GodotScript` annotation takes only one argument:
172
170
173
-
-**className**: If set, the class will be registered with the provided name.
171
+
-**customName**: If set, the class will be registered with the provided name.
174
172
175
173
!!! warning "Unique class names"
176
-
If you specify the `className` in the annotation, you have to make sure that this name is unique! We implemented compilation checks to make sure the compilation fails if more than two classes are registered with the same name, but we cannot check class names from other scripting languages like GDScript or C#! It is also recommended installing our intellij plugin as it shows duplicated registered class names in the editor as an error.
174
+
If you specify the `customName` in the annotation, you have to make sure that this name is unique! We implemented compilation checks to make sure the compilation fails if more than two classes are registered with the same name, but we cannot check class names from other scripting languages like GDScript or C#! It is also recommended installing our intellij plugin as it shows duplicated registered class names in the editor as an error.
177
175
178
176
179
177
## Tool Mode
180
178
181
-
Annotate your class with `@Tool` to make it a tool class (note that `@RegisterClass` is required for this annotation to take effect).
179
+
Annotate your class with `@Tool` to make it a tool class.
Copy file name to clipboardExpand all lines: docs/src/doc/user-guide/properties.md
+8-10
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
Any property of a registered class can be registered as long as it is public, mutable and can be converted to a `Variant`.
2
-
To register a property annotate it with `@RegisterProperty`.
2
+
To register a property annotate it with `@GodotMember`.
3
3
4
4
```kotlin
5
-
@RegisterClass
5
+
@GodotScript
6
6
classRotatingCube: Node3D() {
7
-
@RegisterProperty
7
+
@GodotMember
8
8
var someString:String="Hello there :-)"
9
9
10
-
@RegisterProperty
10
+
@GodotMember
11
11
var propertyWithDefaultValue:Float=2f
12
12
}
13
13
```
@@ -19,32 +19,30 @@ your properties are actually registered as `snake_case`. So a property `someFlag
19
19
20
20
## Core type specifics
21
21
22
-
Godot core type always need to have a value. Hence you cannot register properties of core types (like `Vector3`) with lateinit.
22
+
Godot core type always need to have a value. Hence, you cannot register properties of core types (like `Vector3`) with lateinit.
23
23
24
24
## Exporting properties
25
25
26
-
A registered property can be exported (a.k.a make it visible in the Godot editor) by annotating it with `@Export`.
26
+
A property can be exported (a.k.a. make it visible in the Godot editor) by annotating it with `@Export`.
27
27
A property can be exported if it is a core type, a primitive or inherits from `godot.RefCounted`.
28
28
29
29
```kotlin
30
-
@RegisterClass
30
+
@GodotMember
31
31
classRotatingCube: Node3D() {
32
32
@Export
33
-
@RegisterProperty
34
33
var speed:Float=2f
35
34
}
36
35
```
37
36
38
37
Exported properties can have default values (`2f` in the example above) which will be used as a default value by the `inspector`.
39
-
A default value can **only** contain compile time constants and only references to compile time constants.
40
38
41
39
!!! danger
42
40
If you set a default value in code and a different value in the `inspector` the value of the latter will override the value in code after `init` and before `_enter_tree`.
43
41
44
42
## Type hint registration
45
43
46
44
This module provides a plethora of annotations for defining property type hints.
47
-
These annotations controls how Godot display the property in the inspector.
45
+
These annotations control how Godot display the property in the inspector.
48
46
Each property hint annotation can only be added to certain types of properties.
49
47
Using the wrong annotation will make the compilation fail. These will only take effect if the property is exported.
0 commit comments