Skip to content

Commit b194734

Browse files
committed
wip
Made BTRoot cleanups and made it to not check for entry point in processing.
1 parent a301ac3 commit b194734

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

addons/behaviour_toolkit/behaviour_tree/bt_root.gd

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ enum ProcessType {
2727
@export var blackboard: Blackboard
2828

2929

30-
var active: bool = false
30+
var active: bool = false:
31+
set(value):
32+
active = value
33+
if value and entry_point != null:
34+
_setup_processing()
35+
print("Activated ", str(name))
36+
else:
37+
set_physics_process(false)
38+
set_process(false)
39+
3140
var current_status: BTBehaviour.BTStatus
3241

3342

@@ -36,7 +45,7 @@ var current_status: BTBehaviour.BTStatus
3645
@onready var __connect_child_order_changed: int = \
3746
child_order_changed.connect(_on_child_order_changed)
3847

39-
@onready var entry_point: Node = get_child(0)
48+
@onready var entry_point: BTBehaviour = get_entry_point()
4049

4150

4251
func _validate_property(property: Dictionary) -> void:
@@ -46,22 +55,22 @@ func _validate_property(property: Dictionary) -> void:
4655

4756

4857
func _ready() -> void:
58+
#set_physics_process(false)
59+
#set_process(false)
60+
4961
if Engine.is_editor_hint():
5062
set_physics_process(false)
5163
set_process(false)
5264
return
5365

5466
if blackboard == null:
5567
blackboard = _create_local_blackboard()
56-
57-
if autostart:
68+
69+
if entry_point == null:
70+
return
71+
elif autostart:
5872
active = true
5973

60-
if not process_type:
61-
process_type = ProcessType.PHYSICS
62-
63-
_setup_processing()
64-
6574

6675
## Swap this [BTRoot] nodes current entry point with the provided one.
6776
## If root has no [BTBehaviour] as a child the provided one will be added.
@@ -92,9 +101,6 @@ func _process(delta: float) -> void:
92101

93102

94103
func _process_code(delta: float) -> void:
95-
if entry_point == null:
96-
return
97-
98104
if not active:
99105
return
100106

@@ -117,8 +123,16 @@ func _setup_processing() -> void:
117123
set_process(process_type == ProcessType.IDLE)
118124

119125

126+
func get_entry_point() -> BTBehaviour:
127+
var first_child := get_child(0)
128+
if first_child is BTBehaviour:
129+
return first_child
130+
else:
131+
return null
132+
133+
120134
func _on_child_order_changed() -> void:
121135
if Engine.is_editor_hint():
122136
return
123137

124-
entry_point = get_child(0)
138+
entry_point = get_entry_point()

addons/behaviour_toolkit/finite_state_machine/fsm_state_integrated_bt.gd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ func _on_update(_delta: float, _actor: Node, _blackboard: Blackboard) -> void:
5656
if behaviour_tree == null:
5757
return
5858

59-
if behaviour_tree.current_status == on_status:
60-
if fire_event_on_status:
61-
get_parent().fire_event(event)
59+
if behaviour_tree.current_status == on_status and fire_event_on_status:
60+
get_parent().fire_event(event)
6261

6362

6463
## Executes before the state is exited.

tmp/test.gd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
extends Node2D
2+
3+
4+
@onready var bt_root: BTRoot = $BTRoot as BTRoot
5+
6+
7+
func _unhandled_input(event: InputEvent) -> void:
8+
if Input.is_action_just_pressed("ui_accept"):
9+
if bt_root.active == true:
10+
bt_root.active = false
11+
else:
12+
bt_root.active = true
13+
14+
if Input.is_action_just_pressed("ui_left"):
15+
var lp = LeafPrint.new()
16+
lp.custom_text = "I'm a leaf."
17+
bt_root.add_child(lp)

tmp/test.tscn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://bb5leiis4ldhe"]
2+
3+
[ext_resource type="Script" path="res://tmp/test.gd" id="1_7baav"]
4+
[ext_resource type="Script" path="res://addons/behaviour_toolkit/behaviour_tree/bt_root.gd" id="2_efrcf"]
5+
6+
[node name="Test" type="Node2D"]
7+
script = ExtResource("1_7baav")
8+
9+
[node name="BTRoot" type="Node" parent="."]
10+
script = ExtResource("2_efrcf")

0 commit comments

Comments
 (0)