derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
679 stars 33 forks source link

compound_state.gd Parse Error #128

Open huwpascoe opened 1 week ago

huwpascoe commented 1 week ago

Getting an error when plugin warnings are enabled

Parse Error: The method "add_child()" overrides a method from native class "Node". This won't be called by the engine and may not work as expected. https://github.com/derkork/godot-statecharts/blob/bbe60233d288a4a9241f6b61248ab9e8c52f5da7/addons/godot_state_charts/compound_state.gd#L221-L222

Can be achieved with signals instead, maybe something like:

func _init() -> void:
    if Engine.is_editor_hint():
        child_entered_tree.connect(func(node: Node):
            if initial_state.is_empty() and node is StateChartState:
                (func(): initial_state = get_path_to(node)).call_deferred()
        )
derkork commented 1 week ago

Thanks a lot for reporting this and providing a fix! Funny enough the current implementation works even if the warning says otherwise but the signal way should also do the trick and doesn't trigger a warning. I'm currently away from the computer for a few days, so I will fix this when I get back.