Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3406186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:35:49+00:00 2026-05-18T05:35:49+00:00

I am attempting to create a behavior tree using C#. For anyone who doesn’t

  • 0

I am attempting to create a “behavior tree” using C#.

For anyone who doesn’t know, a behavior tree is basically a framework that you can construct an AI around. There are Sequencers, Selectors, Decorators, composite actions, and other things.

I have found a single library that has implimented a “behavior tree” in C#, located here (http://code.google.com/p/treesharp/) but I cannot understand how to actually use it since there is no example code I can draw from. Could anyone here perhaps make some simple example code that shows how to actually use this framework.. or perhaps you know of another way to impliment a behavior tree in C#?

Thanks so much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:35:50+00:00Added an answer on May 18, 2026 at 5:35 am

    I just looked at that implementation and I find myself wondering why so much code is needed for something relatively simple.

    From what you say, you want a simple way of composing behaviours. A behaviour here, I presume, is a mapping from a state to zero or more actions by an agent. You can model this very easily using C# lambdas. For example:

    Action Selector(Func<bool> cond, Action ifTrue, Action ifFalse) {
      return () => { if cond() then ifTrue() else ifFalse() };
    }
    
    Action Sequencer(Action a, Action b) {
      return () => { a(); b(); }
    }
    

    The leaves of your tree are simple Actions that do something appropriate to the state. You “run” a tree simply by executing it.

    If you want to get fancy, you can parameterise this scheme to make the state explicit.

    Hope this helps.

    —- Addendum —-

    Jason asked for an example of how you could use this approach, so here’s a simple “AI” patrolling guard example (I assume WorldState corresponds to a description of the environment at the time the behaviour tree is evaluated):

    Func<bool> ifPlayerIsInSight = () => ...true iff WorldState shows guard can see player...;
    
    Action shootAtPlayer = () => { ...aim guard's weapon at player and fire... };
    
    Func<bool> ifUnderFire = () => ...true iff WorldState shows guard hears player gunfire...;
    
    Action takeCover = () => { ...guard runs for nearest shelter... };
    
    Action walkBackAndForthGuardingDoorway = () => { ...default guard patrol behaviour... };
    
    Action patrollingGuardBehaviour =
      Selector(ifPlayerIsInSight, shootAtPlayer,
        Selector(ifUnderFire, takeCover,
          walkBackAndForthGuardingDoorway));
    

    To make the guard do something, just call patrollingGuardBehaviour(). Note that the various subactions and tests can be implemented as methods with the right signatures rather than inline as lambdas. You can add other combinators to Selector and Sequencer, e.g., for parallel activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
I'm currently attempting to create a tabbed interface in a web application, and based
I am attempting to create a small application to collect data received from an
I am attempting to create new membership users in an Ektron CMS400.NET-based website by
I'm attempting to create my first real C# application - a small pet project
I'm attempting to load a dll into MSSQL with: USE dbname GO CREATE ASSEMBLY
I am attempting to build a simple method that creates an XML file from
I'm attempting to authenticate a user against ADAM using a user I created in
I am attempting to re-implement the Copy behavior for a QTextEdit object. The custom
(Using Delphi 5) I am attempting to open a log file using the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.