Calling an animation player in a game into another script

Godot Version

Godot Engine v4.2.2 stable


Hello !

I would like to ask for help in how I can call the animation player in the game in another script?
The point is that there is player.tscn in which there is an animation player that contains the animations that I would need in another script.
Thanks in advance for the help.

Use Autoloads, search in google that godot autoloads for learn more, otherwise I am mentioning the steps for it:

  1. Create a script, name it Global
  2. Go to project settings > autoloads
  3. Add the Global script in autoloads
  4. Add a variable player = null in that script
  5. In player ready function do like Global.player = self
  6. Now you can use the animation player from another script like Global.player.get_node(“AnimationPlayer”).play()

Also there are many ways like signals, etc