Godot Version
4.1.2
Question
I am utilizing a version of the mediator pattern using Godot’s built in signals. I have a main parent Node with children that act as components for physics, rendering, etc. The structure of my Scenetree is to practice some design patterns in Godot and GDScript.
Whenever a component needs to communicate data with another component, it does so by speaking with the parent “Game” Node. The Game node then sends out the data to all of its components. The component that is meant to use that data then observes it and processes it.
All of these nodes inherit from a generic component class that has includes a basic send
signal and a _receive()
function. Both list the same number of parameters in the same order, and all inheriting classes of that class have nearly the same pattern. The singular difference are the names of the arguments in the header of the original class and the inheriting class, something I did to make it easier to connect things properly. None of the parameters in any signal or function is typed, so that can’t be the issue.
The send
signal of a component is connected to another node’s _receive()
function. In every connection, I did it via the interface instead of code. Because it is a custom receiving function for a signal, I use the “Pick” option in the editor. The _receive()
function appears in the list of options that are viable according to the editor. I haven’t experimented with connecting the signals in code since the editor’s interface should accomplish the same thing.
I require the use of parameters/arguments in this for: 1. the data contents that are being communicated, 2. a String purpose which components can choose themselves what they do based on it.
Unfortunately, whenever I emit the send signal from any component, usually like so:
send.emit(“set_input_vector”, input_vector)
it results in the same kind of error:
component.gd:154 @ method(): Error calling from signal ‘send’ to callable: ‘Node(game.gd)::_receive’: Method expected 0 arguments, but called with 2.
I am passing one or more parameters, but the receiving method expects zero arguments, regardless of what node is sending and what node is receiving. In all nodes, the receiving method has defined arguments in its header, so I am confused. Is this a bug or am I missing something?