### Setup Gradle Wrapper Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/setting-up.md Initializes the Gradle wrapper for the project, ensuring a consistent Gradle version for builds. Replace '8.1' with your desired Gradle version. ```shell gradle wrapper --gradle-version=8.1 ``` -------------------------------- ### GUT Doubled Script Initialization Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/harness/tests/addons/gut/double_templates/script_template.txt Initializes variables for GUT's doubled script functionality, including paths, stubber/spy/gut IDs, singleton name, and method doubling status. This setup is crucial for the testing framework to identify and manage doubled objects. ```gdscript var __gutdbl_values = { thepath = '{path}', subpath = '{subpath}', stubber = {stubber_id}, sppy = {spy_id}, gut = {gut_id}, from_singleton = '{singleton_name}', is_partial = {is_partial}, doubled_methods = {doubled_methods}, } var __gutdbl = load('res://addons/gut/double_tools.gd').new(self) ``` -------------------------------- ### Set JAVA_HOME on macOS Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/requirements.md On macOS, GUI applications may not inherit environment variables from the shell. Use `launchctl` to set the JAVA_HOME environment variable for applications started from the GUI. ```shell launchctl setenv JAVA_HOME pathtoyourjava ``` -------------------------------- ### Registering a Kotlin Class and Function Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/functions.md Annotate your Kotlin class with `@RegisterClass` and the function you want to expose to Godot with `@RegisterFunction`. This example registers the `_ready` virtual function for a `RotatingCube` node. ```kotlin import godot.core.* import godot.annotation.* @RegisterClass class RotatingCube: Node3D() { @RegisterFunction override fun _ready() { println("I am ready!") } } ``` -------------------------------- ### Debug Kotlin Daemon Compilation Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/knowledge-base/entry-generation.md To debug the Kotlin compiler plugin, run this Gradle command. It starts a new daemon and halts compilation until a remote debugger is attached. Note that this disables incremental builds and significantly slows down compilation. ```bash ./gradlew kspKotlin -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket\,address=8765\,server=y\,suspend=y" ``` -------------------------------- ### Create Project Files (Windows) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/setting-up.md Creates the necessary empty build configuration files for a Gradle project on Windows. ```shell fsutil file createnew build.gradle.kts 0 fsutil file createnew gradle.properties 0 fsutil file createnew settings.gradle.kts 0 ``` -------------------------------- ### Configure GraalVM iOS Export Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/exporting.md Enable iOS export for GraalVM and specify the GraalVM installation directory. Ensure you are using GraalVM 23.1.3 for iOS exports. ```kotlin godot { graalVmDirectory.set(File("Path to your graalVM install")) // or setup GRAALVM_HOME environment variable. isIOSExportEnabled.set(true) } ``` -------------------------------- ### Create Project Files (Unix) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/setting-up.md Creates the necessary empty build configuration files for a Gradle project on Unix-based systems. ```shell touch build.gradle.kts gradle.properties settings.gradle.kts ``` -------------------------------- ### Run Documentation Locally Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/README.md Execute these commands in the terminal to make the documentation accessible via a local web server. This includes making the script executable and running it. ```shell chmod +x run.sh ./run.sh ``` -------------------------------- ### Build Release Version (Windows) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/compiling-your-project.md Build a release version of your project on Windows by adding the '-Prelease' parameter to your Gradle build command. Release builds are recommended for distribution. ```shell gradlew build -Prelease ``` -------------------------------- ### Modify Collection Elements in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/api-differences.md When working with collections like VariantArray and Dictionary, direct modification of retrieved elements is not supported. Use the provided lambda-based get method to modify elements in place. ```kotlin array[index].y += 10f dictionary["foo"].y += 5f ``` ```kotlin array.get(index) { y += 10f } dictionary.get("foo") { y += 5f } ``` -------------------------------- ### Configure Build Script for Maven Local Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/setup.md Configure your project's `build.gradle.kts` and `settings.gradle.kts` files to use the local Maven repository and the Godot Kotlin/JVM plugin. ```kotlin pluginManagement { repositories { mavenLocal() mavenCentral() gradlePluginPortal() google() } resolutionStrategy.eachPlugin { if (requested.id.id == "com.utopia-rise.godot-kotlin-jvm") { useModule("com.utopia-rise:godot-gradle-plugin:${requested.version}") } } } ``` -------------------------------- ### Runtime Configuration: JSON vs. Command-Line Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Configure runtime arguments for the binding using either command-line flags or a `godot_kotlin_configuration.json` file. Command-line flags take precedence over JSON values. ```json // godot_kotlin_configuration.json { "vm_type": "jvm", "use_debug": true, "debug_port": 5005, "debug_address": "localhost", "wait_for_debugger": true, "jmx_port": 5006, "max_string_size": 1024, "disable_gc": false, "custom_jvm_args": ["-Xmx2g", "-Xms512m"] } ``` ```shell # Equivalent command-line usage ./GodotGame \ --jvm-vm-type=jvm \ --jvm-debug-port=5005 \ --jvm-wait-for-debugger=true \ --jvm-max-string-size=1024 \ --jvm-custom-args="-Xmx2g,-Xms512m" # Suppress Kotlin version compatibility check (advanced, gradle.properties) # godot.jvm.suppressKotlinIncompatibility=true ``` -------------------------------- ### Build Release Version (Unix) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/compiling-your-project.md Build a release version of your project on Unix-based systems (Linux/macOS) by adding the '-Prelease' parameter to your Gradle build command. Release builds are recommended for distribution. ```bash ./gradlew build -Prelease ``` -------------------------------- ### Locally Deploy Kotlin JVM Module Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/test-change-from-branch.md Build and publish the kotlin-jvm module to your local Maven repository. The '-Prelease=true' flag is used for publishing. ```bash ./gradlew :tools-common:publishToMavenLocal publishToMavenLocal && ./gradlew publishToMavenLocal -Prelease=true ``` -------------------------------- ### Create Embedded JVM for Testing (arm64) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/setup.md Generate a minimal Java Runtime Environment (JRE) using jlink for arm64 systems, specifically for Apple Silicon Macs. This is required for building and running tests. ```bash jlink --add-modules java.base,java.logging --output jvm/jre-arm64- ``` -------------------------------- ### Class Lifecycle Initialization and Destruction Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/classes.md Utilize the `init` block for initialization logic and override the `_onDestroy` function for cleanup tasks when a class instance is created or destroyed. ```kotlin @RegisterClass class RotatingCube: Node3D() { init { println("Initializing RotatingCube!") } override fun _onDestroy() { println("Cleaning up RotatingCube!") } } ``` -------------------------------- ### Build the Project with Gradle Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/your-first-class.md Execute the Gradle build command to compile your Kotlin code and generate the necessary files for Godot integration. This step is required before you can use your custom classes in the Godot editor. ```shell ./gradlew build ``` -------------------------------- ### Create a JRE with JDWP Agent Module Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/debugging.md Use the `jlink` command to create a custom JRE that includes the `jdk.jdwp.agent` module, necessary for remote debugging. Ensure you specify the correct output path and module names for your system architecture. ```bash jlink --add-modules java.base,java.logging,jdk.jdwp.agent --output jvm/jre-amd64-linux ``` ```bash jlink --add-modules java.base,java.logging,jdk.jdwp.agent --output jvm/jre-arm64-macos ``` -------------------------------- ### Create Embedded JVM for Testing (amd64) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/setup.md Generate a minimal Java Runtime Environment (JRE) using jlink for amd64 systems. This is necessary for building and running tests for the Kotlin/JVM module. ```bash jlink --add-modules java.base,java.logging --output jvm/jre-amd64- ``` -------------------------------- ### Run Godot Editor with Mono Support Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/build-with-csharp-support.md Execute the compiled Godot editor binary that includes Mono support. The path may vary based on your platform and build configuration. ```bash ../../.. /bin/godot.linuxbsd.editor.x86_64.mono ``` -------------------------------- ### Connecting Signals with Kotlin Lambdas Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Demonstrates how to use Kotlin lambdas directly to subscribe to signals, providing a concise way to handle signal emissions without defining separate methods. ```kotlin mySignal.connect { println("This message has been written by a Kotlin Lambda") } ``` -------------------------------- ### Connecting Signals with Callables in Java Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Illustrates three ways to connect a signal to a registered method in Java. Since method reference syntax is not available for Java in this context, explicit Callable creation is used, with options for snake_case naming. ```java @RegisterClass public class SomeObject extends Object { @RegisterFunction public void onReverseChanged(boolean reverse) { System.out.println("Value of reverse has changed: " + reverse); } } @RegisterClass public class AnotherObject extends Object { @RegisterSignal("reverse") public Signal1 mySignal = Signal1.create(this, "mySignal"); private SomeObject targetObject = new SomeObject(); public AnotherObject() { // Here are 3 different ways to connect a signal to a registered method. The method reference syntax is not implemented for Java. mySignal.connect(Callable.create(targetObject, StringNames.toGodotName("onReverseChanged"))); // The recommanded way. mySignal.connect(Callable.create(targetObject, "on_reverse_changed")); // Unsafe, try to use snake_case in your code as least as possible. connect("my_signal", Callable.create(targetObject, "on_reverse_changed")); // Really, don't do that. } } ``` -------------------------------- ### Set Custom JVM Arguments Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/advanced/commandline-args-and-configuration.md Use `--jvm-custom-args` to provide specific arguments to the JVM. Ensure arguments are valid to prevent startup issues. For command-line usage, pass a quoted space-separated list or a comma-separated list. Alternatively, use `custom_jvm_args` with a list of strings in configuration files. ```bash --jvm-custom-args="-Xmx4g -Xms4g" ``` ```bash --jvm-custom-args=-Xmx4g,-Xms4g ``` ```kotlin custom_jvm_args=["-Xmx4g", "-Xms4g"] ``` -------------------------------- ### Check Built Plugin Version Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/test-change-from-branch.md List the contents of the local Maven repository for the godot-gradle-plugin to verify the version that was built. ```bash ls ~/.m2/repository/com/utopia-rise/godot-gradle-plugin/ ``` -------------------------------- ### Automate Bootstrap JAR Copy with Gradle Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/setup.md This Gradle task automates copying the `godot-bootstrap.jar` to the Godot engine's bin directory after evaluation. It's useful for local development but should not be committed to version control. ```kotlin afterEvaluate { tasks { val bootstrapJar = getByName("bootstrapJar") val copyBootstrapJar by creating(Copy::class.java) { group = "godot-jvm" from(bootstrapJar) destinationDir = File("${projectDir.absolutePath}/../../../../bin/") dependsOn(bootstrapJar) println(File("${projectDir.absolutePath}/../../../../bin/").absolutePath) } build.get().dependsOn(copyBootstrapJar) } } ``` -------------------------------- ### Library build.gradle.kts Configuration Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Configure your library's build.gradle.kts file to set a class prefix, project name, and disable registration file generation for the library itself. ```kotlin plugins { kotlin("jvm") version "2.3.20" id("com.utopia-rise.godot-kotlin-jvm") version "0.16.0-4.6.2" } godot { // Prefix all registered class names to avoid consumer naming conflicts classPrefix = "MyLib" // Name of the library — consumers get gdj files under dependencies/my-library/ projectName = "my-library" // Disable .gdj generation for the library itself (not needed unless // the library project also has sample scenes) isRegistrationFileGenerationEnabled = false } ``` -------------------------------- ### Configure build.gradle.kts Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/setting-up.md Configures the main Gradle build script for a Godot Kotlin/JVM project, applying necessary plugins and repositories. Ensure you replace `$kotlinVersion` and `$godotKotlinVersion` with the actual versions. ```kotlin plugins { kotlin("jvm") version "$kotlinVersion" id("com.utopia-rise.godot-kotlin-jvm") version "$godotKotlinVersion" } repositories { mavenCentral() } ``` -------------------------------- ### Compile Godot with Mono Support Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/build-with-csharp-support.md Use this command to compile the Godot engine with C# support enabled. Ensure you have fulfilled the prerequisites for compiling with Mono. ```bash scons p= tools=yes module_mono_enabled=yes mono_glue=no ``` -------------------------------- ### Configure Registration File Destination Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/api-differences.md Customize the base directory for generated registration files (.gdj) in your build.gradle.kts file. ```kotlin godot { registrationFileBaseDir.set() } ``` -------------------------------- ### Build Godot Engine Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/test-change-from-branch.md Build the Godot engine from source with debug symbols and development build enabled. ```bash scons debug_symbols=yes dev_build=yes ``` -------------------------------- ### Creating Callables in Java Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Shows how to create a NativeCallable referencing a Godot Object's method and a LambdaCallable1 for custom logic. ```java NativeCallable regularCallable = Callable.create(myObject, "myMethod".toGodotName()); LambdaCallable1 customCallable = LambdaCallable1.create( Void.class, String.class, (string) -> { System.out.println(string); } ); ``` -------------------------------- ### Configure GraalVM Native Image with Resources Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/advanced/graal-vm-native-image.md Include resource files in the GraalVM native image build. Specify additional configuration files for JNI, reflection, and resources. ```kotlin godot { isGraalNativeImageExportEnabled.set(true) graalVmDirectory.set(File(System.getenv("GRAALVM_HOME"))) windowsDeveloperVCVarsPath.set(File(System.getenv("VC_VARS_PATH"))) additionalGraalJniConfigurationFiles.set(arrayOf("my-jni-configuration-file.json", "another-conf.json")) additionalGraalReflectionConfigurationFiles.set(arrayOf("my-reflection-configuration-file.json", "another-conf.json")) additionalGraalResourceConfigurationFiles.set(arrayOf("my-resource-configuration-file.json", "another-conf.json")) } ``` -------------------------------- ### Configure GraalVM Native Image with JNI and Reflection Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/advanced/graal-vm-native-image.md Add configurations for JNI and reflection when using GraalVM native image. Specify additional configuration files for JNI and reflection. ```kotlin godot { isGraalNativeImageExportEnabled.set(true) graalVmDirectory.set(File(System.getenv("GRAALVM_HOME"))) windowsDeveloperVCVarsPath.set(File(System.getenv("VC_VARS_PATH"))) additionalGraalJniConfigurationFiles.set(arrayOf("my-jni-configuration-file.json", "another-conf.json")) additionalGraalReflectionConfigurationFiles.set(arrayOf("my-reflection-configuration-file.json", "another-conf.json")) } ``` -------------------------------- ### Connecting Signals with Callables in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Demonstrates four methods for connecting a signal to a registered method in Kotlin. The recommended approach uses a function reference. Other methods involve creating a Callable explicitly, with variations for snake_case naming. ```kotlin @RegisterClass class SomeObject: Object() { @RegisterFunction fun onReverseChanged(reverse: Boolean) { println("Value of reverse has changed: $reverse") } } @RegisterClass class AnotherObject: Object() { @RegisterSignal("reverse") val mySignal by signal1() private val targetObject = SomeObject() init { // Here are 4 different ways to connect a signal to a registered method mySignal.connect(targetObject, targetObject::onReverseChanged) // The recommanded way. Create a Callable behind the hood. mySignal.connect(Callable(targetObject, "onReverseChanged".toGodotName())) // Second pick, use it if you can't have a function reference. mySignal.connect(Callable(targetObject, "on_reverse_changed")) // Unsafe, try to use snake_case in your code as least as possible. connect("my_signal", Callable(targetObject, "on_reverse_changed")) // Really, don't do that. } } ``` -------------------------------- ### Checkout Specific Branch for Kotlin JVM Module Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/test-change-from-branch.md Navigate into the kotlin_jvm module directory and checkout the specific branch you want to test. ```bash git checkout ``` -------------------------------- ### Build Debug Version (Windows) Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/compiling-your-project.md Execute a standard Gradle build on Windows to create a debug version of your project. This is the default build type. ```shell gradlew build ``` -------------------------------- ### Enable Fully Qualified Name Registration Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/classes.md Configure your `build.gradle.kts` to enable registration using fully qualified names. This prefixes class names with their package structure, further reducing naming conflicts. ```kotlin godot { isFqNameRegistrationEnabled.set(true) } ``` -------------------------------- ### Create Embedded JRE for amd64 Linux Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/exporting.md Use the `jlink` command to create a minimal JRE for amd64 Linux systems. This JRE will be embedded in your exported game. ```shell jlink --add-modules java.base,java.logging --output jvm/jre-amd64-linux ``` -------------------------------- ### Creating Callables in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Demonstrates creating a NativeCallable referencing a Godot Object's method and a custom lambda callable. ```kotlin val regularCallable = NativeCallable(myObject, MyObject::myMethod) val customCallable = callable1 { println(it) } ``` -------------------------------- ### Configure Godot Kotlin/JVM Project with Gradle Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Configure project dependencies, compiler plugin, and Godot-specific settings like registration file output, class name registration, coroutines, and export options for Android and GraalVM Native Image. ```kotlin // settings.gradle.kts rootProject.name = "my-godot-game" // build.gradle.kts plugins { kotlin("jvm") version "2.3.20" id("com.utopia-rise.godot-kotlin-jvm") version "0.16.0-4.6.2" } repositories { mavenCentral() } godot { // Where .gdj registration files are generated (default: "gdj/") registrationFileBaseDir.set(projectDir.resolve("gdj")) // Flatten registration files instead of mirroring package hierarchy isRegistrationFileHierarchyEnabled.set(false) // Register class names as fully qualified names to avoid conflicts isFqNameRegistrationEnabled.set(true) // Enable Kotlin coroutines support (adds kotlinx.coroutines dependency) isGodotCoroutinesEnabled.set(true) // Enable Android export (requires Android SDK with build tools >= 35) isAndroidExportEnabled.set(true) d8ToolPath = File("${System.getenv("ANDROID_SDK_ROOT")}/build-tools/36.0.0/d8") androidCompileSdkDir = File("${System.getenv("ANDROID_SDK_ROOT")}/platforms/android-36") androidMinApi = 21 // Enable GraalVM Native Image export (desktop only) isGraalNativeImageExportEnabled.set(true) graalVmDirectory.set(File(System.getenv("GRAALVM_HOME"))) windowsDeveloperVCVarsPath.set(File(System.getenv("VC_VARS_PATH"))) // Windows only } ``` -------------------------------- ### Add Regular JVM Library Dependency Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/consuming-libraries.md Use this snippet to include any standard JVM library in your project. Ensure you replace 'some.library:some-artifact:' with the actual coordinates of the library you wish to use. ```kotlin // build.gradle.kts dependencies { implementation("some.library:some-artifact:") } ``` -------------------------------- ### Set LD_PRELOAD for JRE Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/build-with-csharp-support.md Preload the JRE's libjsig.so library to ensure proper JRE functionality during runtime. Adjust the path and architecture (amd64/arm64) as needed for your project and system. ```bash export LD_PRELOAD=/jre-{amd64|arm64}/lib/libjsig.so ``` -------------------------------- ### Create Embedded JRE for arm64 macOS Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/exporting.md Use the `jlink` command to create a minimal JRE for arm64 macOS systems. This JRE will be embedded in your exported game. ```shell jlink --add-modules java.base,java.logging --output jvm/jre-arm64-macos ``` -------------------------------- ### Build Godot Engine with Kotlin/JVM Module Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/setup.md Compile the Godot engine with the Kotlin/JVM module integrated. Replace 'linuxbsd' with your target platform (e.g., windows, macos). ```bash scons platform=linuxbsd ``` -------------------------------- ### Configure Custom Source Directories in build.gradle.kts Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/advanced/custom-src-dirs.md Add custom source directories to your main source set by modifying the `build.gradle.kts` file. This allows Gradle to find your Kotlin files in non-standard locations. ```kotlin kotlin.sourceSets.main { kotlin.srcDirs("scripts") } ``` -------------------------------- ### Generate Mono Glue Code Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/build-with-csharp-support.md This command generates the necessary C# glue code for Mono integration. It requires a Java Runtime Environment (JRE) in the godot-root folder and a godot-bootstrap.jar in the bin subdirectory. ```bash --generate-mono-glue modules/mono/glue ``` -------------------------------- ### Consumer build.gradle.kts Dependency Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Add the library as a regular Gradle dependency in the consumer's build.gradle.kts file. The .gdj registration files will be automatically generated in the consumer's project. ```kotlin // Consumer build.gradle.kts — use the library like any Gradle dependency dependencies { implementation("com.example:my-library:1.0.0") } // After build, gdj/dependencies/my-library/MyLibInventory.gdj is generated // and can be attached to nodes in the Godot editor. ``` -------------------------------- ### Enable GraalVM Native Image Export Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/advanced/graal-vm-native-image.md Configure the Gradle plugin to enable GraalVM native image export. Ensure GRAALVM_HOME and VC_VARS_PATH are set. ```kotlin godot { isGraalNativeImageExportEnabled.set(true) graalVmDirectory.set(File(System.getenv("GRAALVM_HOME"))) windowsDeveloperVCVarsPath.set(File(System.getenv("VC_VARS_PATH"))) } ``` -------------------------------- ### GraalVM Native Image Export Configuration Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Configure the Gradle plugin to enable GraalVM Native Image export for desktop platforms to eliminate JVM startup overhead. Provide reflection and JNI config files for libraries using reflection. ```kotlin // build.gradle.kts — GraalVM Native Image configuration godot { isGraalNativeImageExportEnabled.set(true) graalVmDirectory.set(File(System.getenv("GRAALVM_HOME"))) windowsDeveloperVCVarsPath.set( // Windows only File(System.getenv("VC_VARS_PATH")) ) // Additional config files for libraries that use reflection / JNI additionalGraalJniConfigurationFiles.set( arrayOf("graal/jni-config.json") ) additionalGraalReflectionConfigurationFiles.set( arrayOf("graal/reflection-config.json") ) additionalGraalResourceConfigurationFiles.set( arrayOf("graal/resource-config.json") ) } ``` ```shell # Build the native image ./gradlew build # Run the game forcing GraalVM Native Image VM type ./GodotEditor --jvm-vm-type=graal_native_image # Or set it permanently in godot_kotlin_configuration.json at project root: # { "vm_type": "graal_native_image" } ``` -------------------------------- ### Set d8 Tool Path Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/exporting.md Manually set the path to the d8 build tool if the ANDROID_SDK_ROOT environment variable is not set or if a specific version is required. ```kotlin godot { d8ToolPath = File("${System.getenv("ANDROID_SDK_ROOT")}/build-tools/36.0.0/d8") } ``` -------------------------------- ### Declare, Emit, and Connect Typed Signals in Godot Kotlin/JVM Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Use delegate syntax with `signal()`, `signal1()`, etc., and `@RegisterSignal` to declare signals. Connect using function references for compile-time type safety. Emit signals with their respective `emit()` methods. ```kotlin import godot.Node import godot.annotation.RegisterClass import godot.annotation.RegisterFunction import godot.annotation.RegisterSignal import godot.signals.signal import godot.signals.signal1 import godot.signals.signal2 @RegisterClass class HealthComponent : Node() { // Zero-argument signal (delegate form — recommended, lightweight) @RegisterSignal val died by signal() // One-argument signal with named parameter @RegisterSignal("newHealth") val healthChanged by signal1() // Two-argument signal @RegisterSignal("attacker", "damage") val damageTaken by signal2() @RegisterProperty var health: Float = 100f @RegisterFunction fun takeDamage(attacker: Node, amount: Float) { health -= amount damageTaken.emit(attacker, amount) // type-safe emit healthChanged.emit(health) if (health <= 0f) { died.emit() } } } @RegisterClass class HUDManager : Node() { private val healthComp = HealthComponent() @RegisterFunction fun onHealthChanged(newHealth: Float) { GD.print("HP updated: $newHealth") } @RegisterFunction fun onDied() { GD.print("Player died!") } @RegisterFunction override fun _ready() { // Recommended: connect via function reference (type-checked at compile time) healthComp.healthChanged.connect(this, HUDManager::onHealthChanged) // Connect zero-arg signal healthComp.died.connect(this, HUDManager::onDied) // Connect with a lambda (no registration needed) healthComp.damageTaken.connect { attacker, damage -> GD.print("${attacker.name} dealt $damage damage") } } } ``` -------------------------------- ### Fix gradlew Permissions on Linux/macOS Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/getting-started/compiling-your-project.md If you encounter errors when building from the Godot editor on Linux or macOS, you may need to make the gradlew script executable. Run this command in your terminal. ```shell chmod +x gradlew ``` -------------------------------- ### Logging with GD Singleton in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/api-differences.md Use the GD singleton's print functions to ensure logs appear in both the CLI and the Godot Editor's output panel. Standard Kotlin print functions only output to the CLI. ```kotlin GD.print("Hello There!") ``` -------------------------------- ### Instantiate Kotlin Class in GDScript Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/classes.md Use this to create an instance of a Kotlin class from GDScript. Only the default no-argument constructor is supported for direct instantiation. Properties can be set after creation. ```gdscript var instance := YourKotlinClass.new() ``` -------------------------------- ### Library Class Registration Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Define a library class using annotations like @RegisterClass, @Export, and @RegisterFunction. The classPrefix from the Gradle configuration will be prepended to the registered class name. ```kotlin // Library class — registered as "MyLibInventory" due to classPrefix @RegisterClass class Inventory : Node() { @Export @RegisterProperty var capacity: Int = 20 @RegisterFunction fun addItem(itemName: String): Boolean { GD.print("Adding $itemName to inventory") return true } } ``` -------------------------------- ### Implement Coroutines with `godotCoroutine` and Signal Suspension Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Enable coroutines via the Gradle plugin and use the `godotCoroutine` builder. Signals provide an `await()` suspend function to pause coroutines until the signal is emitted. ```kotlin import godot.Node import godot.annotation.RegisterClass import godot.annotation.RegisterFunction import godot.annotation.RegisterSignal import godot.coroutines.godotCoroutine import godot.signals.signal1 @RegisterClass class DialogSystem : Node() { @RegisterSignal("text") val dialogLineFinished by signal1() @RegisterFunction fun playDialog() = godotCoroutine { GD.print("Line 1") dialogLineFinished.await() // suspend until signal emits GD.print("Line 2") dialogLineFinished.await() GD.print("Dialog complete") } @RegisterFunction fun advanceDialog(line: String) { dialogLineFinished.emit(line) // resumes the suspended coroutine } } ``` -------------------------------- ### Instantiate Godot Types in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/api-differences.md Create new instances of Godot's built-in types directly using their constructors. ```kotlin val node3D = Node3D() val vec = Vector3() ``` -------------------------------- ### Access Godot Singletons in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/api-differences.md Interact with Godot's global singletons as Kotlin objects, calling their methods directly. ```kotlin Physics2DServer.areaGetTransform(area) ``` -------------------------------- ### Configure IntelliJ for Remote JVM Debugging Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/debugging.md Set up a new 'Remote JVM Debug' configuration in IntelliJ IDEA. Ensure the 'Port' field matches the port specified in Godot's run arguments (e.g., 5005). ```plaintext 5005 ``` -------------------------------- ### Configure Gradle Plugin Resolution Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/test-change-from-branch.md Configure your project's `pluginManagement` block to resolve the custom godot-kotlin-jvm Gradle plugin using `useModule`. ```kotlin pluginManagement { // ... resolutionStrategy.eachPlugin { if (requested.id.id == "com.utopia-rise.godot-kotlin-jvm") { useModule("com.utopia-rise:godot-gradle-plugin:${requested.version}") } } } ``` -------------------------------- ### Registering Kotlin Functions for Godot Source: https://context7.com/utopia-rise/godot-kotlin-jvm/llms.txt Expose Kotlin functions to Godot and other scripting languages using @RegisterFunction. Overridden virtual functions like _ready must also be annotated. Supports RPC for networked multiplayer. ```kotlin import godot.Node import godot.annotation.RegisterClass import godot.annotation.RegisterFunction import godot.global.GD import godot.MultiplayerPeer @RegisterClass class GameManager : Node() { // Overriding a virtual function — must annotate to register @RegisterFunction override fun _ready() { GD.print("GameManager is ready") } // Custom function callable from GDScript as game_manager.deal_damage(target, 50) @RegisterFunction fun dealDamage(target: Node, amount: Int) { GD.print("Dealing $amount damage to ${target.name}") } // RPC function — callable over the network @RegisterFunction(rpcMode = MultiplayerPeer.RPCMode.RPC_MODE_ANY_PEER) fun syncPosition(x: Float, y: Float, z: Float) { val pos = position pos.x = x; pos.y = y; pos.z = z position = pos } // Functions with more than 16 parameters are not supported; // use a container type instead: @RegisterFunction fun applyConfig(config: Dictionary) { val hp = config["health"] as Float val spd = config["speed"] as Float GD.print("Applying config: hp=$hp, spd=$spd") } } // GDScript: game_manager.deal_damage(some_node, 50) // GDScript RPC: game_manager.rpc("sync_position", x, y, z) ``` -------------------------------- ### Enable Coroutines in build.gradle Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/coroutines.md Add this configuration to your build.gradle file to enable the Godot coroutines feature. This automatically includes necessary dependencies. ```kotlin godot { isGodotCoroutinesEnabled.set(true) } ``` -------------------------------- ### Creating Callables in Scala Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Illustrates creating a Callable referencing a Godot Object's method and a LambdaCallable1 for custom logic. ```scala val regularCallable = Callable.create(this, "myMethod".toGodotName()) val customCallable = LambdaCallable1.create( classOf[Void], classOf[String], (string: String) => { println(string); } ) ``` -------------------------------- ### Check Published Artifact Version Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/contribution/setup.md Verify the version of the published Godot Gradle plugin in your local Maven repository. This helps confirm that the publishing step was successful. ```bash ls ~/.m2/repository/com/utopia-rise/godot-gradle-plugin ``` -------------------------------- ### Register a Kotlin Class Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/classes.md To expose a Kotlin class to Godot, it must extend `godot.Object` (or a subtype) and be annotated with `@RegisterClass`. This generates necessary registration files. ```kotlin import godot.Node3D import godot.annotation.RegisterClass @RegisterClass class RotatingCube: Node3D() { // ... } ``` -------------------------------- ### Registering Custom Signals in Kotlin Source: https://github.com/utopia-rise/godot-kotlin-jvm/blob/master/docs/src/doc/user-guide/signals_and_callables.md Two methods for declaring custom signals in Kotlin scripts: using a delegate (recommended) or a backing field. Both require @RegisterSignal annotation with parameter names. ```kotlin @RegisterClass class MyScript: Node() { @RegisterSignal("reverse") val mySignal by signal1() @RegisterSignal("reverse") val mySignal = Signal1("mySignal") } ```