How would you compose scripts that need to know about their parent?

Godot Version

4.3

Question

Say I have a Rotate script that rotates a Node3D. I also have a Bob script that moves a Node3D up and down in space. Combing these two scripts causes a Node3D to both rotate and bob up and down.

The main problem I have is that most solutions that come to mind require the child nodes to know about the parent node. Signalling up doesn’t really work in this case because the parent is just a dumb Node3D object. I can make them siblings to better respect the rule, I guess, but…

Which way would you prefer to set up your scene and scripts?

Here are some ways that come to mind:

Option 1: get_parent()

Scene structure:

Node3DObject
- RotateNode
- BobNode

Rotate or Bob script:

func _process(delta: float) -> void:
	var parent: Node = get_parent()
	if parent is Node3D:
		# Rotate or bob the parent here

Option 2: @ export parent

Scene structure:

Node3DObject
- RotateNode
- BobNode

Rotate or Bob script:

@export var target: Node3D # connect Node3DObject to this
# Rotate or bob target in _process

Option 3: @ export sibling

Scene structure:

Node3DObject
RotateNode
BobNode

Rotate or Bob script:

@export var target: Node3D # connect Node3DObject to this
# Rotate or bob target in _process

Any ideas for other options? Which way would you do it for your game?

Option 2 is the way is would go for

1 Like