Skip to content

Commit

Permalink
Fix initialize source behaviorTree in awake
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiKurisu committed Feb 20, 2024
1 parent 29c38a7 commit 96db8fd
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Runtime/Core/BehaviorTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ public class BehaviorTree : MonoBehaviour, IBehaviorTree

[HideInInspector, SerializeReference]
protected Root root = new();
public Root Root => root;
public Root Root
{
get => root;
set
{
root = value;
//Runtime setup root
if (Application.isPlaying)
{
SharedVariableMapper.Traverse(this);
root.Run(gameObject, this);
root.Awake();
root.Start();
}
}
}
Object IBehaviorTree._Object => gameObject;
[HideInInspector, SerializeReference]
protected List<SharedVariable> sharedVariables = new();
Expand All @@ -43,20 +58,10 @@ private void Awake()
root = instance.Root;
}
this.MapGlobal();
if (externalBehaviorTree)
{
//Prevent remap for external tree
if (!externalBehaviorTree.IsInitialized)
externalBehaviorTree.Initialize();
}
else
{
SharedVariableMapper.Traverse(this);
}
SharedVariableMapper.Traverse(this);
root.Run(gameObject, this);
root.Awake();
}

private void Start()
{
root.Start();
Expand Down

0 comments on commit 96db8fd

Please sign in to comment.