Node based state machine somehow no longer acknowledge "player"

Godot Version

<stable4.2>

Question

<Hi. Im using node based state machine to create my player character. A while ago, I changed the file name (e.g. player to Player, entities to Entities) and now player state class no longer acknowledge player (owner) if I added new state node. Every state node which was created previously works fine, but only in newly created state node, the player state class does not recognize player as owner. Does anyone have any idea why and how to fixe this problem?

class_name PlayerState
extends State

# Typed reference to the player node.
var player: Player


func _ready() -> void:
	# The states are children of the `Player` node so their `_ready()` callback will execute first.
	# That's why we wait for the `owner` to be ready first.
	await owner.ready
	# The `as` keyword casts the `owner` variable to the `Player` type.
	# If the `owner` is not a `Player`, we'll get `null`.
	player = owner as Player
	# This check will tell us if we inadvertently assign a derived state script
	# in a scene other than `Player.tscn`, which would be unintended. This can
	# help prevent some bugs that are difficult to understand.
	assert(player != null)

inside newly added state node extended script:

extends PlayerState

# Called when the node enters the scene tree for the first time.
func _ready():
	print("state event")
	player.player_cannot_move = true
	player.can_shoot = false

I get an error Invalid set 'player_cannot_move(on base: 'Nill') with value of type 'bool'. I do have exact same code inside other state node which was created before I changed the file name and never had this issue before.

Since it extends PlayerState it is overriding the previous _ready() function. You need to call the inherited _ready in addition to your own. Use super._ready() for this.

extends PlayerState

# Called when the node enters the scene tree for the first time.
func _ready():
	await super._ready() # in this case needs await

	print("state event")
	player.player_cannot_move = true
	player.can_shoot = false

I think I am so stupid. I was forgetting to rewrite _ready() to func enter(_msg := {}) -> void: