Most efficient way to have an instanced scene target another single instanced scene when multiple exist?

Godot Version

v4.2.stable.official [46dc27791]


I’m currently building out the level system for a game that will rely heavily on machines, placed in the level, that need to interact with other machines. Examples of these machines include input machines: switches, buttons, sensors; logic machines: timers, logic gates, signal delayers; and output machines: flamethrowers, saws, doors.

An example of a level interaction might be: A switch has a timer as its activation target, when it’s switched on, it will activate the timer. After the timer is finished, it will activate a set of doors to begin closing.


What would the most efficient way be to assign a machine a list of “activation targets” (other machines) and then have it be able to efficiently call a function on those targets?

My Conceptual Solution

In theory, I imagine the best way to do this would be to give each instanced machine a unique identifier and then give every machine an activation_targets array that contains the id’s of every machine it wants to activate when X condition is met. I also assume for performance reasons, when a level is loaded, every machine with activation targets should find and then store the paths of the machines in the list.

The difficulty I’m having, is figuring out how to do this in godot with it’s instanced scene system as I’m rather new to the engine.

Instead of an array of IDs make it an array of Node references. This way when a level loads you don’t need to “find” nodes by ID, you already have references. And by having them you can call any functions required for activation.

On a question of how to fill that array. If the machines are placed in the scene at design-time (that’s in the editor scenes) then you fill it at design time as well. If the machines are instantiated during runtime (that’s when the game runs) then you add references to the array when you connect machines (in whatever way you do this, you didn’t specify).

My instinct is to use signals to determine when given button is clicked and to react to this.

Making it as a activation_targest sounds like implementing coupling into the code. Its desired that each instance decides on their own and using signals fit this idea best.