Skip to content

Commit 32fa022

Browse files
committed
Fix Earewien#3 : Custom performance monitor in BTRoot produces erros when node is removed from tree
1 parent dade29f commit 32fa022

File tree

1 file changed

+12
-1
lines changed
  • addons/yet_another_behavior_tree/src/Nodes

1 file changed

+12
-1
lines changed

addons/yet_another_behavior_tree/src/Nodes/BTRoot.gd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ var _execution_blackboard:BTBlackboard
5353
var _execution_start_time_ms:float
5454
var _execution_stop_time_ms:float
5555

56+
@onready var _performance_monitor_identifier:String = "BTRoot/%s-%s" % [get_name(), get_instance_id()]
57+
5658
#------------------------------------------
5759
# Fonctions Godot redéfinies
5860
#------------------------------------------
@@ -69,7 +71,9 @@ func _ready() -> void:
6971
_blackboard = BTBlackboard.new()
7072

7173
if not Engine.is_editor_hint():
72-
Performance.add_custom_monitor("BTRoot/%s-%s" % [get_name(), get_instance_id()], _compute_last_exec_time)
74+
_add_custom_performance_monitor()
75+
tree_entered.connect(_add_custom_performance_monitor)
76+
tree_exited.connect(_remove_custom_performance_monitor)
7377

7478
func _process(delta:float) -> void:
7579
if not Engine.is_editor_hint() and enabled and root_process_mode == BTRootProcessMode.PROCESS:
@@ -133,6 +137,13 @@ func _do_execute(delta:float):
133137
_previous_running_nodes = running_nodes
134138
_register_execution_stop()
135139

140+
func _add_custom_performance_monitor() -> void:
141+
if not Performance.has_custom_monitor(_performance_monitor_identifier):
142+
Performance.add_custom_monitor(_performance_monitor_identifier, _compute_last_exec_time)
143+
144+
func _remove_custom_performance_monitor() -> void:
145+
if Performance.has_custom_monitor(_performance_monitor_identifier):
146+
Performance.remove_custom_monitor(_performance_monitor_identifier)
136147

137148
func _register_execution_start() -> void:
138149
_execution_start_time_ms = Time.get_ticks_msec()

0 commit comments

Comments
 (0)