Godot 4 Help Understanding Signals
Hello all!
Like most people I find myself a recent refugee from the Unity fiasco. I’ve been trying to prototype a project in Godot and I’ve been running into an issue I would think would be pretty easy to find a solution to as it seems to be a pretty fundamental building block of any project in Godot. Perhaps I’m misunderstanding how to accomplish this in Godot, but essentially I’m instantiating a number of tiles to be used for a grid system in my game. I want these tiles to be able to emit their index and transform values and then have other scripts pick this information up as needed. From what I’ve read signals are the way to do this, however whenever I try to send a signal with or without parameters nothing seems to happen. I seem to be able to connect to the signal just fine but the method doesn’t seem to be called.
Here’s an example of me defining the signal and then emitting it:
<span style="color:#323232;">signal index_transform()
</span><span style="color:#323232;">
</span><span style="color:#323232;">index_transform.emit()
</span>
And here’s how I am connecting and attempting to call the method in a secondary script:
<span style="color:#323232;">func _ready() -> void:
</span><span style="color:#323232;"> var hexGrid = get_node("/root/Main/Map/HexGrid")
</span><span style="color:#323232;"> hexGrid.index_transform.connect(Callable(self, "_get_hex_index_transform"))
</span><span style="color:#323232;">
</span><span style="color:#323232;">func _get_hex_index_transform():
</span><span style="color:#323232;"> print("I'm Connected")
</span>
And when I’m passing parameters from what I understand I should only have to include the parameters like so:
<span style="color:#323232;">signal index_transform(index, transform)
</span><span style="color:#323232;">
</span><span style="color:#323232;">index_transform.emit(tile_index, tile_coordinates)
</span>
<span style="color:#323232;">func _ready() -> void:
</span><span style="color:#323232;"> var hexGrid = get_node("/root/Main/Map/HexGrid")
</span><span style="color:#323232;"> hexGrid.index_transform.connect(Callable(self, "_get_hex_index_transform"))
</span><span style="color:#323232;">
</span><span style="color:#323232;">func _get_hex_index_transform(index, transform):
</span><span style="color:#323232;"> print("I'm Connected")
</span><span style="color:#323232;"> print("INDEX: ", index," POS: ", transform)
</span>
However neither of these seem to work. What am I doing wrong?
Add comment