how do i directly access the child of an object

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

Node2D
KineticBodyPlayer <<<
Sprite1
CollisionShape2D

the script is inside kineticbodyplayer, what do i have to type in to directly access the attributes of sprite?
something like this:

self.GetChild().Sprite1.FlipH = true
:bust_in_silhouette: Reply From: kidscancode

This is what get_node() is for. In the case you described, on the KinematicBody2D, you would use GetNode("Sprite").

It would be get_node("Sprite1"), not GetNode("Sprite").

njamster | 2020-07-18 19:47

:bust_in_silhouette: Reply From: njamster

To set the value of the flip_h-property you would do:

get_node("Sprite1").flip_h = true

To get the name of a property you can hover with the mouse over its entry in the Inspector. The tooltip will display the name of the property you can use in your code.

Alternatively you can get the i-th child of a node like this:

get_child(i)

Note that i is zero-indexed, so i = 0 will get you the first child node.