0 votes

My SceneTree:

Game (Node)

Player (KinematicBody2D) (instanced, script attached) (has an AnimatedSprite as a child with animation_finished() connected to the player script)
Ball (RigidBody2D) (instanced, script attached)

In the player script I tried:

func _on_AnimatedSprite_animation_finished():

1. get_tree().get_root().get_node("Ball").my_function()
2. get_tree().get_node("Ball").my_function()
3. get_parent().get_node("Ball").my_function().

How can I call a function on the Ball or change some of its properties?

asked Jun 24 in Engine by MaaaxiKing (291 points)

The thing is I don't know, that when you instance the ball, what is it a child of?? This information is kinda nececarry.

I instanced the scene even before the game has started. The Ball is child of Game.

2 Answers

0 votes
Best answer

I just changed to get_node("/root/Game/Ball").my_function() and now it works.

answered Jun 25 by MaaaxiKing (291 points)
0 votes

I think, that the 1st option should work just fine.
I f you want to change a property of another node you can do it like this:

get_tree().get_root().get_node("name_of_the_node").property = value
answered Jun 25 by Czselu349 (139 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 How to use this Q&A? before posting your first questions.