access sprite of instancied object

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tiernich
:warning: Old Version Published before Godot 3 was released.

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!

:bust_in_silhouette: Reply From: Toger5

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.

haha, so simple! thanks!

tiernich | 2016-03-24 13:53