Topic was automatically imported from the old Question2Answer platform.
Asked By
tiernich
Old Version
Published before Godot 3 was released.
I have an instancied RigidBody:
var obj = obj_scene.instance()
obj.set_global_pos(Vector2(rand_range(120,905),-30))
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.
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.set_global_pos(Vector2(rand_range(120,905),-30))
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.