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/user-guide/api-differences.md
+16-6Lines changed: 16 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,22 +168,32 @@ Currently this feature except abstract classes.
168
168
169
169
## Caching
170
170
171
-
Several Godot functions take `StringName` or `NodePath` as a parameter.
171
+
Several Godot functions take `StringName` or `NodePath` as a parameter.
172
+
It's often more convenient to directly use a String that need to be converted.
172
173
173
-
Extension functions have been provided `String.asStringName()`, `String.asNodePath()` and `StringName.asNodePath()`, to allow for the easy creation of these.
174
-
As an optimisation, these `StringName` and `NodePath` instances are cached to reduce the overhead of creating new instances unnecessarily.
174
+
This operation can be costly so we provide extension functions which cache the result of the conversion for later calls:
175
+
176
+
-`String.asCachedStringName()`
177
+
-`String.asCachedNodePath()`
178
+
-`StringName.asCachedNodePath()`
175
179
176
180
```kotlin
177
181
// This first call to the extension function creates the cache entry.
178
-
val firstCall ="Test".asStringName()
182
+
val firstCall ="Test".asCachedStringName()
179
183
180
184
// This second call for the same String value, will return the previously cached instance.
181
-
val secondCall ="Test".asStringName()
185
+
val secondCall ="Test".asCachedStringName()
182
186
183
187
// This third call will create a second entry in the cache due to the different key value.
184
-
val thirdCall ="OtherTest".asStringName()
188
+
val thirdCall ="OtherTest".asCachedStringName()
185
189
```
186
190
191
+
You can also use the non-cached version of them if you simply want ease of conversion:
192
+
193
+
-`String.asStringName()`
194
+
-`String.asNodePath()`
195
+
-`StringName.asNodePath()`
196
+
187
197
## Logging
188
198
189
199
If you want logs to appear both in CLI and in the Godot Editor you will have to use the print functions inside the `GD` singleton like:
0 commit comments