Tree Control

I have my own Behaviour Tree framework running but it has no visual editor yet. Right now, it’s all code. When I want to make a behaviour, I had to do it like this:


    private void PrepareBehaviourTree() {
        BntSelector root = new BntSelector("Root");


        this.behaviourTree = new BntTree("TrackerBehaviour", root);

    private BntNode PrepareIdle() {
        BntSequence sequence = new BntSequence("Idle");

        // IsIdle
        sequence.AddChild(new BntCondition("IsIdle", delegate() {
            return states.IsIdle();

        return sequence;

    private BntNode PrepareCaptured() {
        BntSequence sequence = new BntSequence("Captured");

        // IsCaptureSuccess
        sequence.AddChild(new BntCondition("IsCaptureSuccess", delegate {
            return states.IsCaptureSuccess();

        return sequence;

    private BntNode PreparePouncing() {
        BntSequence sequence = new BntSequence("Pouncing");

        // IsPouncing
        sequence.AddChild(new BntCondition("IsPouncing", delegate() {
            return states.IsPouncing();

        // InstantActions
        sequence.AddChild(new BntDelegateAction("InstantActions", delegate() {
            // send notification to start capture so that target knows it can't move to another state

            // send notification so that target knows that capture would fail and it would react right away
            // target should already start reacting while tracker is still starting to pounce
            if(!IsCaptureEmminent()) {

            return BntResult.SUCCESS;


        return sequence;


The main advantage of doing it like this is I can be very flexible. I can use any programming/scripting construct to create a Behaviour Tree. For example, I can use closures to add simple function invocation actions. I could use branching to create a different behaviour branch depending on some parameter.

It also has a major disadvantage. It’s messy and I hate messy.

My next big attempt is to create a visual editor. It doesn’t need to have fancy features. For now, I just need the bare minimum features such that I can create a working Behaviour Tree using an editor.

The first step is to create a “Tree Control”. It’s a simple user interface that manipulates items in a tree structure. This is what I’ve come up using some dummy data.

A simple Tree Control
A simple Tree Control

It has the following features for now:

  • Drag to move child to another parent
  • Move child up/down among its siblings
  • Node folding

I actually had fun doing this. It’s like college all over again. I wish I had the skills and knowledge that I have now when we had this assignment. My college implementation was so bad.

It’s a good start. I wonder what to do next.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s