![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Clifford |
Hello !
I’m still studying on scene tree design and ways to pass information from one scene’s child node to another.
I have made my own first design and would like to get insights from others on it in order to get better understanding/mindset.
An example of one feature in the current game:
Inside the Player scene:
The root node has assigned signals for its children to use, one of which is the player_aimed signal. This signal is emitted when the player pressed the aim button.
signal player_aimed(player_sprite_node)
Inside the Test scene:
Using the Godot UI, I connected the player_aimed signal to both the CameraRig and the Gun scenes root node ( _on_Player_player_aimed(player_sprite_node) )
Inside the Gun scene:
The root node receive the signal and uses a setter to flip its _process function on. The _process function sole purpose is to rotate the Gun root node to mouse position by using the passed player_sprite_node information.
Inside the CameraRig scene:
The root node receive the signal and uses a setter to flip its _process function on. The process function sole purpose is to pass the get_camera_screen_center information to the Gun scene by emitting a signal called camera_moved to the Gun scene.
signal camera_moved(camera_global_center)
Inside the Test scene:
Again, I use the engine UI to connect the camera_moved signal from the CameraRig scene to the Gun scene to pass the get_camera_screen_center information.
Inside the Gun scene:
func _on_CameraRig_camera_moved(camera) → void:
do maths stuff that keeps raycast length within viewport
This is because in my game I don’t want the player to be able to shot at things outside the camera view
All in all I’d say there is a lot of signals being emitted back and forth, I have been debating on whether I should make the Test node responsible in connecting its children signals or to keep all the signals in a singleton, but in the end I’m unsure of which to method to use or what direction I should take. I am afraid that with my current design, the game code would grow to become difficult for me to navigate or maintain.
I hope the above is clear, I’d gladly clarify otherwise.
I’d appreciate any comment and feedback on this.
Thank you in advanced for your time and help.