How to Call a Node From Another Scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StrikerSVX

I would love to know how to do this work:

Car = KinematicBody2d
----CarBody = Sprite
----CarColor = Sprite
----No name = ColisionShape2d
----No name = Camera2d

CarColor = Control
----No name = CenterContainer
--------No name = VBoxContainer
------------No name = ColorPickerButton
----------------CarEx = Sprite
----------------ColorEx = Sprite
------------StartButton = Button
------------QuitButton = Button


extends ColorPickerButton

func _process(delta):
	if color:
		$ColorEx.modulate = color

what i need is to change the modulate on the node CarColor in the scene Car.tscn, but i need to do this in the script on the scene CarColor.tscn, can somebody tell me how? please?

Scenes are resources, those need to be instanced to make a tree structure and be able to get references to particular nodes.

Are those scenes instanced and (the instances) assigned to a variable or the scene tree?

eons | 2018-12-17 04:06

No, they are just scenes, i’m not instancing them.

StrikerSVX | 2018-12-17 13:41

:bust_in_silhouette: Reply From: rojekabc

So - you have two separate scenes. And, if I understand well, CarColor is the node inside Car. So - you have to reach Car node and then get from it CarColor node.

If they’re loaded and append to the main world somewhere in the structure, you may do in such way:

var car_color_node = get_world().get_root().get_node("Car").get_node("CarColor")
car_color_node.modulate = color

And you may also do in connected way:

var car_color_node = get_world().get_root().get_node("Car/CarColor")
car_color_node.modulate = color

You may also create variable in your color picker and set it to the node, on which you are working. There’re many options.

if is a child, it should not be world>root>node, but get_tree().get_root().current_scene or get_parent().owner may be better.

But there are many “depends”, like there are no details about where are those scenes.

eons | 2018-12-17 10:52

I tried using this way but i didn’t work
if i use on the ColorPickerButton script it say that nonexistent function get_world in the base colorpickerbutton

i tried using on my control node too but it says the same…

StrikerSVX | 2018-12-17 13:50

It’s my mistake. Use get_tree() not get_world() :slight_smile:

rojekabc | 2018-12-18 13:55