+1 vote

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
in Engine by (13 points)

2 Answers

0 votes

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

by (21,940 points)

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

+4 votes

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.

by (10,586 points)
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.