Signals and reported nonexistent signals #477
-
I know this is a bit more of a Godot issue and a bit less of a SwiftGodot one, so I apologize for that. Historically with other engines I have used a bespoke Event/Message broker to inform objects in a decoupled way. In migrating to (Swift)Godot I am trying to utilize its way of doing things. Signals. I have two classes (trimmed for clarity) with one declaring the signal, and another attempting to connect to that signal. When running the project, the console reports that the declared signal is a nonexistent one and of course the Is this correct thinking on my part? Are we truly needing to pass references around to connect to a signal? Thanks! // GameInterface.swift
import SwiftGodot
@Godot
class GameInterface: CanvasLayer {
// MARK: - Properties
@BindNode var Coins: Label
// MARK: - Functions
override func _ready() {
GD.print("Attempting to connect signal")
connect(signal: Player.coinCollected, to: self, method: "onCoinCollected")
}
@Callable func onCoinCollected(total: Int) {
GD.print("coinCollected signal received.")
Coins.text = "\(total)"
}
} // Player.swift
import SwiftGodot
@Godot
class Player: CharacterBody3D {
// MARK: - Properties
var coins = 0
#signal("coinCollected", arguments: ["count": Int.self])
// MARK: - Functions
func collectCoin() {
GD.print("Coin collected!")
coins += 1
emit(signal: Player.coinCollected, coins)
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The issue is that you are attempting to connect to a signal that is declared on the type Instead, you need to connect to the player, something like:
|
Beta Was this translation helpful? Give feedback.
The issue is that you are attempting to connect to a signal that is declared on the type
Player
on theGameInterface
method.Instead, you need to connect to the player, something like: