NullReferenceExceptions for player state classes

I’ve followed the course well so far but am having difficulty when implementing the steps in this lecture. The _Ready() methods for the idle and move state classes fail because they are not set to an instance of an object (full error text below). This error also occurs when the Flip method is called while the game is running. Is the Player.cs class supposed to be instantiated in the main scene?

E 0:00:00:0974 void PlayerMoveState._Ready(): System.NullReferenceException: Object reference not set to an instance of an object.
<C# Error> System.NullReferenceException
<C# Source> PlayerMoveState.cs:9 @ void PlayerMoveState._Ready()
PlayerMoveState.cs:9 @ void PlayerMoveState._Ready()
Node.cs:2137 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
PlayerMoveState_ScriptMethods.generated.cs:38 @ bool PlayerMoveState.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)

I figured out the issue. In the course of cleaning up some of my file names, I renamed the player.cs script to Player.cs, and just to be safe, I re-attached the script to the Player node. However doing this blanked out the assigned AnimationPlayer and Sprite3D nodes! I re-assigned them in the Godot Inspector, and the errors went away.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms