0 votes

So, I have a player scene that contains the camera setup and bounding box and everything, and a model scene with just the model and its skeleton and animation player (inherited from a GLTF file). If I attach a script to the model scene and try to access the AnimationPlayer node from there, it works just fine, but when I instance the model scene within the the player scene and try to access the node using the following:

    if Input.is_action_pressed("ui_up"):
    speed_mult = 1
    direction -= camera_pivot.transform.basis.z
    model.rotation_degrees.y = ((model.rotation_degrees.y * 3) + camera_pivot.rotation_degrees.y) / 4
    model.AnimationPlayer.play("walk")

I get the error "Invalid get index 'AnimationPlayer' (on base: 'Spatial')." This error seems to occur no matter which child node of the model scene I reference, as I tested it out referencing the Armature node, as well, and got the same error. Even if I add a new child node to the model scene from within the player scene, it gives me the same error.

I'm running Godot version 3.4.2 under Windows 10. Let me know if I need to provide any other information.

Godot version 3.4.2
in Engine by (20 points)

1 Answer

0 votes
Best answer

You just doing it wrong. Child nodes is not available as index. You need to get them with get_node() function. Note, that AnimationPlayer must be direct child of model. like this:

model.get_node("AnimationPlayer").play("walk")

Also, if that node used often, it's recommended to save that node in a variable. Add this to the beginning of the script (see order conventions):

# Remember, that you need to get `model` node first
onready var animation = model.get_node("AnimationPlayer")

After that you can reference it as animation:

animation.play("walk")
by (648 points)
selected by

Thanks for all your help!

You're welcome

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.