X Tutup
Skip to content

[Android] Minor updates to the GodotPlugin APIs#111135

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
m4gr3d:add_emit_signal_overload
Oct 21, 2025
Merged

[Android] Minor updates to the GodotPlugin APIs#111135
Repiteo merged 1 commit intogodotengine:masterfrom
m4gr3d:add_emit_signal_overload

Conversation

@m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented Oct 1, 2025

Minor updates to the GodotPlugin API:

  • Add overload method for GodotPlugin#emitSignal(...) that takes in a SignalInfo argument.
    It's common for GodotPlugin implementations to define a set of SignalInfo objects to use for registration, then reuse those objects when a signal is emitted. This typically looks like:
private val EVENT_SIGNAL = SignalInfo("event_signal")
...
override fun getPluginSignals() = setOf(EVENT_SIGNAL)
...
fun dispatchEvent() {
    emitSignal(EVENT_SIGNAL.name)
}

With this update, the call to emit the signal can be changed to:

fun dispatchEvent() {
    emitSignal(EVENT_SIGNAL)
}
  • Allow passing null values as signal arguments. Prior to this update, the following call would throw an IllegalArgumentException:
private val UPDATE_SIGNAL = SignalInfo("update_signal", String::class.java)
...
fun updateEvent() {
    emitSignal(UPDATE_SIGNAL, null)
}

The update removes this limitation, allowing signal arguments to be null.

@m4gr3d m4gr3d added this to the 4.6 milestone Oct 1, 2025
@m4gr3d m4gr3d requested a review from a team as a code owner October 1, 2025 20:28
@syntaxerror247
Copy link
Member

Could you provide an example usage of this new method?

@m4gr3d m4gr3d force-pushed the add_emit_signal_overload branch from c3b271f to f872a4e Compare October 1, 2025 22:54
@m4gr3d m4gr3d changed the title Add overload method for GodotPlugin#emitSignal(...) [Android] Minor updates to the GodotPlugin APIs Oct 1, 2025
@m4gr3d
Copy link
Contributor Author

m4gr3d commented Oct 1, 2025

Could you provide an example usage of this new method?

@syntaxerror247 I've updated the description with code examples.

@syntaxerror247
Copy link
Member

  • Add overload method for GodotPlugin#emitSignal(...) that takes in a SignalInfo argument.
    It's common for GodotPlugin implementations to define a set of SignalInfo objects to use for registration, then reuse those objects when a signal is emitted. This typically looks like:
private val EVENT_SIGNAL = SignalInfo("event_signal")
...
override fun getPluginSignals() = setOf(EVENT_SIGNAL)
...
fun dispatchEvent() {
    emitSignal(EVENT_SIGNAL.name)
}

With this update, the call to emit the signal can be changed to:

fun dispatchEvent() {
    emitSignal(EVENT_SIGNAL)
}

Hm.. I don't see any use for this overloaded method because you can create string constants for signal names. Eg.

private val EVENT_SIGNAL = "event_signal"
override fun getPluginSignals() = setOf(SignalInfo(EVENT_SIGNAL))
fun dispatchEvent() {
    emitSignal(EVENT_SIGNAL)
}

@syntaxerror247
Copy link
Member

Since you’re working on this, would it be possible to support nullable parameters?
For ex, I have the following method in my plugin:

@UsedByGodot
fun testMethod(param1: String?) {
    if (param1 != null) {
        Log.d("godot-test", param1)
    } else {
        Log.d("godot-test", "param1 is null")
    }
}

when I call plugin_singleton.testMethod(null) from gdscript, it throws an error saying the function doesn’t exist, since it only accepts a string.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Oct 2, 2025

Since you’re working on this, would it be possible to support nullable parameters?
For ex, I have the following method in my plugin:

@UsedByGodot
fun testMethod(param1: String?) {
    if (param1 != null) {
        Log.d("godot-test", param1)
    } else {
        Log.d("godot-test", "param1 is null")
    }
}

when I call plugin_singleton.testMethod(null) from gdscript, it throws an error saying the function doesn’t exist, since it only accepts a string.

Yeah I can take a look!

@m4gr3d m4gr3d force-pushed the add_emit_signal_overload branch from f872a4e to da362a1 Compare October 3, 2025 03:46
@m4gr3d
Copy link
Contributor Author

m4gr3d commented Oct 3, 2025

Since you’re working on this, would it be possible to support nullable parameters? For ex, I have the following method in my plugin:

@UsedByGodot
fun testMethod(param1: String?) {
    if (param1 != null) {
        Log.d("godot-test", param1)
    } else {
        Log.d("godot-test", "param1 is null")
    }
}

when I call plugin_singleton.testMethod(null) from gdscript, it throws an error saying the function doesn’t exist, since it only accepts a string.

@syntaxerror247 I thought on it some more, and I think it's better to keep the current limitation in place for a few reasons:

  • It aligns with gdscript type system. The limitation you mention only applies to String and Callable which matches gdscript static typing when it's enabled. E.g: A String variable in gdscript cannot be assigned null when static typing is enabled.
  • Removing this limitation would be fine when interacting with Java code, but would be an issue when interacting with Kotlin code. From the gdscript side, we can't tell when a String argument to a Kotlin method is a nullable String or a non-nullable String. As such the safe approach is to assume that it's a non-nullable String and prevent passing null because the developer has control over the gdscript code and can modify it to accommodate the limitation (e.g: passing an empty string instead), whereas the Kotlin side can be a third-party library that's unable to be modified, where passing a null value could cause a runtime NullPointerException.
  • Last, as Kotlin and gdscript demonstrate, pushing for null-safety is a safer, more robust approach to development, so we should encourage that approach whenever possible (e.g: passing empty string instead of null values).

@m4gr3d m4gr3d force-pushed the add_emit_signal_overload branch 2 times, most recently from 47e16c4 to c95bd46 Compare October 3, 2025 17:45
@m4gr3d m4gr3d force-pushed the add_emit_signal_overload branch from c95bd46 to bfa6884 Compare October 12, 2025 06:15
- Add overload method for `GodotPlugin#emitSignal(...)`
- Allow passing `null` values as signal arguments
@m4gr3d m4gr3d force-pushed the add_emit_signal_overload branch from bfa6884 to b9c3b1d Compare October 12, 2025 06:17
@Repiteo Repiteo merged commit 58a6412 into godotengine:master Oct 21, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 21, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup