MystikalPooka/Unity-Visual-Behavior-Tree

Improve Efficiency of Tick Method

Closed this issue · 1 comments

Currently the Tick methods set an internal state that the parents must then check. This is not required any more since we are using reactive extensions which alleviates the problems with using coroutines that can only return IEnumerator. Having tick methods return the state immediately would be more efficient and much easier to work with.

UPDATE: Actually thinking this might be better to return a stream of states, rather than just a single state. This will be the most reactive and will enable complex behaviors to be streamed anywhere using just extensions like return Observable.Interval(TimeSpan.FromSeconds(1)).Do(Debug.Log("Every second forever!").... Etc,etc. This will allow long-running behaviors to be able to run completely concurrent with other behaviors without having to wait for ticks from their parent before updating.

It will also allow complex parent subscription behavior:

void Start() {
child.Tick().Do(Debug.Log("This occurs whenever this child ticks!")).Subscribe().AddTo(this)
}

void Start() {
child.Tick().Where(state => state.equals(BehaviorState.Failure)).Do(Debug.Log("This occurs whenever the child returns a failure state")).Subscribe().AddTo(this)
}

etc... Further testing and updates to come!