+1 vote

I have an instancied RigidBody:

var obj = obj_scene.instance()

has you can see i do some changes in is global position.
But i want access the sprite of the RigidBody to change his color or alpha. but after some research and tries, have no succeed.

thanks in advance!

in Engine by (429 points)

1 Answer

+1 vote
Best answer

To access child objects you use the get_node("node_name") function.
This is a function from the Node object. So very node objects can use it.
What you have to do is:

var obj = obj_scene.instance()
obj.get_node("Sprite").set_opacity ( float opacity ) #for the opacity
obj.set_modulate ( Color modulate ) #for the color

because you only can acces children with the get_node() function you have use the root "prefix": get_node("/root/firstNodeInNodeTree/MyParentNode/TheNodeIWantToAcces")
to acces any node in your current scene. The advantage is that you can have nodes with the same name in a scene if they do have different parents.

by (333 points)
selected by

haha, so simple! thanks!

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.