Strange error upon checking children for specified type

Godot Version

4.7.stable

Question

The error I’m getting is: Expression is of type “Node” so it can’t be of type “State”.

extends Node
class_name StateMachine

var states : Array[State]

func initialize(_entity : Entity) -> void:
	states = []
	for c in get_children():
		if c is State: # Error here
			states.append(c)

In the scene tree, state_machine.gd (see above) is attached to StateMachine (Node) as a child of Player (CharacterBody2D)

StateMachine has one child (Node) with an attached script which extends State

state_machine.gd has no other owners.

I have tried:

  • reloading the project
  • deleting StateMachine and re-attaching state_machine.gd
  • closing all other scenes and scripts, then closing and re-opening godot
  • double checking that any and all children of StateMachine have scripts attached which extend State

Any suggestions?

Where do you define class_name State? Can you share that script?

It seems your State class does not extend from a Node type, so there would be no way a child node could be of type State.

You’re so right I can’t believe I didn’t check that. I had initially started doing my states as resources. Thank you. Sorry lol