Quick architecture question

Godot Version

4.4

Question

Hello, I’m new to Godot, I hope this is an appropriate question.

I have a gameLevel (Node2D) scene. It has a player (CharacterBody2D) as a child. Additionally, I have a minigun (Node2D) scene.

The minigun is instanced to the gameLevel, and it needs information on player position. I have been sending information down the tree by calling a method of the child from the parent. However, not all gameLevels have a minigun. I would like to not modify my gameLevel.gd script each time based on if the gameLevel has a minigun or not.

What would be the best way to get that information from gameLevel to minigun, such that I can just drop the minigun into the level and not change any code on the parent script?

This is a good use case for signals. Send a signal with the information you need to transmit to the minigun, and have the minigun connect to the signal.

1 Like