Targeting an object in another scene

I have made a world scene that includes a model planetarium in which the model sun moves in synchronization with the DirectionalLight3D that is lighting the scene, using this simple script attached to the model sun:

extends Node3D

@export var target: Node3D

func _process(delta):
global_rotation=target.global_rotation

This gives me a field in the Inspector that lets me assign a target for the model to synchronize its rotation value with.

Now I want to make the whole model planetarium it’s own scene with “Save Branch as Scene…”. But when I do that, the script in the “model scene” can no longer target an object in the “world scene”. The field in the inspector only lets me pick from nodes that are in the same scene.

What would be the best way to do to link the model sun in the model scene with the DirectLight3D in the world scene?

If the model scene script is on the scene’s top node, you can assign the exported variable to its instance in the world scene, instead from within the scene.

I moved the script from the model sun to the root node of the planetarium model and modified it like this:

extends Node3D

@export var target: Node3D
var modelsun: Node3D

func _ready():
   modelsun = get_node(“Model Sun”)

func _process(delta):
   modelsun.global_rotation=sun.global_rotation

With Model Sun being a child node of the Planetarium scene root node.

If I add the planetarium scene as a node to the world scene, selecting it there shows the Target field in the Inspector where I can assign the DirectLight3D as the target.

And works just like it should.