Animation Player issue when using Autoload

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

I’m still new to Godot, and I ran into a problem while trying to make a small game. I was trying to be able to use a variable from my CharacterBody3D (which id called “Golem”) script into an Area3D script, so I used Autoload with the CharacterBody3D script. But then I discovered that whenever I put the script on Autoload (no matter if enabled or not) and started the scene, the AnimationPlayer of my CharacterBody3D, which is completely unrelated in this whole thing, had this error

Attempt to call function ‘play’ in base ‘null instance’ on a null instance.

This is the part of the code it’s referring to:

func _process(_delta):
if Input.is_action_pressed("ui_right"):
	$AnimationPlayer.play("GolemWalk")
elif Input.is_action_pressed("ui_left"):
	$AnimationPlayer.play("GolemWalk")
elif Input.is_action_pressed("ui_up"):
	$AnimationPlayer.play("GolemWalk")
elif Input.is_action_pressed("ui_down"):
	$AnimationPlayer.play("GolemWalk")
else:
	$AnimationPlayer.play("GolemStand")

So you’re trying to autoload the script that includes this code snippet?

TRAILtheGREAT | 2023-04-29 18:01

No, that’s the point. I posted this snippet because the error point to the last line of this section of code. The variable I autoloaded the code for is in a different function:
if is_on_floor(): return true

GearStrife05 | 2023-05-01 20:20

Sorry, I misinterpreted your question: Yes, this snippet is part of the script I autoloaded

GearStrife05 | 2023-05-02 09:35