Godot Version
4.6.2
Question
I’m building a hierarchical state machine, with a custom class “State”.
The state class has the boolis_superstate, which exposes different variables depending on if its true or false. To do this, the class (and each script extending State) needs the @tool annotation.
The problem: the StateMachine class has a function which iterates over all its children, connects them to the player, and then does the same for each of their children. Since I might want to add components or other nodes under the state machine, the function also ignores the child if child == State fails:
extends Node
class_name StateMachine
func _assign_actor(_actor: Player, parent: Node) -> void:
for child in parent.get_children():
if child == State:
child.actor = _actor
_assign_actor(_actor, child)
However, a custom class starting with the @tool annotation is not recognised as the custom class, but as the class it inherits from (in this case Node). I also tried to get the script of the child and match its name to the class string, but child.get_script().get_global_name() returns blank.
I could do without the @tool annotation, I just think it’s neat to use, and was mainly wondering if anyone knows a solution to this?
