Skip to content

Commit

Permalink
Dont override actor in _ready if already defined (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarTides authored Feb 8, 2024
1 parent 4da9279 commit f877108
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions addons/beehave/nodes/beehave_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ func _ready() -> void:
if not process_thread:
process_thread = ProcessThread.PHYSICS

if actor_node_path:
actor = get_node(actor_node_path)
else:
actor = get_parent()
if not actor:
if actor_node_path:
actor = get_node(actor_node_path)
else:
actor = get_parent()

if not blackboard:
# invoke setter to auto-initialise the blackboard.
Expand Down
10 changes: 10 additions & 0 deletions test/beehave_tree_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ func test_blackboard_not_initialized() -> void:
tree.add_child(always_succeed)
var result = tree.tick()
assert_that(result).is_equal(BeehaveNode.SUCCESS)


func test_actor_override() -> void:
var scene = create_scene()
scene_runner(scene)
var tree = create_tree()
var actor = auto_free(Node2D.new())
tree.actor = actor
scene.add_child(tree)
assert_that(tree.actor).is_equal(actor)

0 comments on commit f877108

Please sign in to comment.