Why does this crash when trying to change the animation?

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

I’m reading from the official Godot 4 docs on the part of coding the player choosing the animations.

Here is the code part I am using to change the animation

func _process(delta):
	if Input.is_action_pressed("right"):
		$Sprite2D/AnimationPlayer.animation = "walk"

But when I run the game and press right the game crashes.

and the error says

W 0:00:00:0694   The parameter 'delta' is never used in the function '_process'. If this is intended, prefix it with an underscore: '_delta'
  <GDScript Source>CharacterBody2D.gd:31

What’s going on here?

:bust_in_silhouette: Reply From: jgodfrey

The “error” you mention isn’t an error at all. It’s just a warning telling you that the _process() function has an input argument (delta) that you are not using in the function (which isn’t typical). That said, it is just a warning and you can safely ignore if you didn’t intend to use the argument. There are a number of ways to tell the engine that you don’t want to be warned about this case. A simple way, as suggested in the warning message itself, is to simply rename the argument to _delta. So…

func _process(_delta)

That underscore will tell the engine to no longer warn about that specific argument.

So, while interesting, this has nothing to do with a “crash”. If you’re really getting a crash, you’ll need to provide some additional info.

Ok, the underscore was just a typo. But the game still crashes when I hit Right.

Here is a screenshot of my screen when the game crashes.

godot_help.png - Google Drive

GamesByMike | 2023-06-10 19:21

An AnimationPlayer doesn’t have an animation property. So, that’s what’s causing the error in your screenshot.

Maybe you wanted current_animation instead?

See the docs here:

AnimationPlayer — Godot Engine (3.4) documentation in English

jgodfrey | 2023-06-10 19:29

It took some trial and error, but It works now! Thanks!

GamesByMike | 2023-06-11 19:44