"Invalid get index" error on all child nodes of a GLTF import

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

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.

:bust_in_silhouette: Reply From: USBashka

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")

Thanks for all your help!

enceladus | 2022-07-16 17:14

You’re welcome

USBashka | 2022-07-16 17:29