Is underscore ignored in GDScript?

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

I am trying to get an animations length.
I load the animation_player onready and also the animations length.
The Animation is called Attack_1

onready var attack1Length = animation_player.get_animation('Attack_1').length

gives me an

Invalid get index 'Attack_1' (on base: 'AnimationNodeStateMachinePlayback')

Nevertheless if I remove the underscore and searching for an Attack1 animation, I’ll get an Invalid get Index 'length' (on base: 'null instance') error.

What do I do wrong?

From the looks of the error, the object animation_player is of the class AnimationNodeStateMachinePlayback which doesn’t have the method get_animation(). Are you sure the object is an AnimationPlayer? Could it be AnimationTree or some other related class?

Ertain | 2023-02-12 22:50

:bust_in_silhouette: Reply From: BR14Nx

Thanks to the hint of @Ertain I noticed I was looking at the completely wrong position.

I had further code behind the attack1Length which I didn’t post here. I was multipling this at the end:

state_machine.Attack_1.TimeScale

turns out I was not using the index correctly.
I thought the problem lays in the first half since I printed out that part of code with a print() and it also gave me the error, but I assume I was only trying the wrong indication of Attack1 and didn’t try Attack_1.