0 votes

Hi everyone.

I have a question about working with signals. In my main scene, I have a 'Control' (Node2D) node, which is a parent to all object who have interaction (coins, the player, etc). And a UI node, which is the parent of all UI elements.

It seems reasonable to decouple these two as much as possible, and only let them interact with signals. So I made the following setup:

The starry things is where a script on that node emits a signal. In this way, the 'Control' node needs to know the structure of it's children, but the UI node shouldn't care. I like this setup, since control and UI are decoupled quite nicely.

However.. In this case, an event from the 'Coin' node needs to be emitted 3 times, before the data ends up in the UI node. That seems like a lot..

My question is:

Is this an OK way to do this? Is it lacking in performance, or am I maybe overthinking things?

Thanks in advance for your help.

Godot version 3.2.3
in Engine by (15 points)

1 Answer

+1 vote
Best answer

You can have 50 000 functions calls in a tic without much issues (if they are fast), so 3 when a player collects a coin is not an issue. It might make stacktraces and the debugger slightly harder to read however.

You are overthinking things but it is not necessarily a bad thing. The biggest danger to your game is that you loose motivation, so having fun in coding is a consideration, and you seem to enjoy your layout.

Having your Node2D named Control know each of it's children seems cumbersome. They could operate the connections of Control signals to their own, and modify variables in "Control" that emit signals on set (see setget).

Also consider that you an create signals on the fly with add_user_signal, and override _set and _get to create fake properties (as well as launching signals on set).

PS: Please, do not name a Node2D "Control", this will confuse people. Consider using "Controller", or "Model".

by (2,720 points)
selected by

You're right, I should really change the name of that node, it's very confusing atm. The setget suggestion would really help in this example, that's kind of what I was looking for. Thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.