0 votes

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?

in Engine by (99 points)

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?

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

1 Answer

0 votes
Best answer

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.

by (166 points)
selected by

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.

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...

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.