Skip to content

Commit

Permalink
Fix reloading scene debug issue (#310)
Browse files Browse the repository at this point in the history
* 🐛 unregister behaviour tree from debugging when removed from scene

* Fix tabs being spaces, I hope

* Check if active tree is valid before trying to do things with it
  • Loading branch information
zeroregard authored Feb 16, 2024
1 parent f877108 commit 2ebcde6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions addons/beehave/debug/global_debugger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func _on_debug_message(message: String, data: Array) -> bool:
_set_active_tree(data[0])
return true
if message == "visibility_changed":
if _active_tree:
if _active_tree && is_instance_valid(_active_tree):
_active_tree._can_send_message = data[0]
return true
return false
Expand All @@ -24,7 +24,7 @@ func _set_active_tree(tree_id: int) -> void:
if not tree:
return

if _active_tree:
if _active_tree && is_instance_valid(_active_tree):
_active_tree._can_send_message = false
_active_tree = tree
_active_tree._can_send_message = true
Expand Down
13 changes: 9 additions & 4 deletions addons/beehave/nodes/beehave_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@ func _on_scene_tree_node_added_removed(node: Node, is_added: bool) -> void:

if node is BeehaveNode and is_ancestor_of(node):
var sgnal := node.ready if is_added else node.tree_exited
sgnal.connect(
func() -> void: BeehaveDebuggerMessages.register_tree(_get_debugger_data(self)),
CONNECT_ONE_SHOT
)
if is_added:
sgnal.connect(
func() -> void: BeehaveDebuggerMessages.register_tree(_get_debugger_data(self)),
CONNECT_ONE_SHOT
)
else:
sgnal.connect(
func() -> void: BeehaveDebuggerMessages.unregister_tree(get_instance_id())
)


func _physics_process(_delta: float) -> void:
Expand Down

0 comments on commit 2ebcde6

Please sign in to comment.