Advertisement

Fuzzy Logic in Unreal Engine's Behavior Tree

Started by March 22, 2018 09:30 PM
7 comments, last by AudioGoose45 6 years, 8 months ago

Hi all,

I’m a game development student, and I am currently working on a project for a class that involves creating a prototype for an AI system. Specifically, I am attempting to create an AI that will alter the way enemy characters attack the player based primarily on what other enemy characters are present. For example, a close-range enemy might rush the player if it is alone but, if there are ranged enemies present as well, it will hold back to protect those characters. I hope to have these behaviors influenced by a few factors, including the number of enemy characters, the types of enemy characters present, and map features. The purpose is to have an artificial intelligence that behaves in a strategic manner based on what is happening in the game world, rather than a simple “attack the player on sight” behavior. The project will be completed in Unreal Engine, and I do have experience working with the engine’s blackboards and behavior trees; I have created a simple AI in the past that alternated between patrolling along a predetermined route and attacking the player based on proximity.

Based on research I have done, it would seem a fuzzy logic system, such as a utility-based structure, would be more appropriate for this kind of AI, rather than something more binary like Unreal’s built-in behavior tree system, since the AI’s behavior is influenced by a few different factors. I was wondering if someone might advise me as to some methods by which I might get this “fuzzy” effect from a behavior tree? As I mentioned, I am still new to artificial intelligence programming, and I appreciate any advice that might be offered! Thank you in advance.

Unreal's AI system is much more than just the behavior tree. What you are describing is very easy to do in Unreal 4 and if you don't want to use Unreal's AI tools you don't need to. Unreal's tools are exactly that, just tools that you can use it and not use it as you want.

With that said why wouldn't you use a behavior tree for this? I could do this easily with a behavior tree and some enums. Note I am not a programmer so I am really interested in this answer.

Advertisement

Hi Scouting Ninja,

I am honestly fairly new to AI programming and entirely new to fuzzy logic, so it's very possible I am overthinking the problem. Most of my limited knowledge is theoretical, rather than practical; from what I've read behavior trees are typically more binary, so the result would be more concrete, rather than flexible. What I envision when working with a behavior tree based on my past experience is more "if x conditions are met, always do y response." Given I have a handful of non-binary variables, I imagine this might be a bit less flexible than I desire and grow more complicated than it would need to be compared to if I used a less binary AI structure. My purposes in moving away from a behavior tree was partially due to this hope to increase efficiency, and partially a desire to expand my knowledge of AI programming, since I have only worked with behavior trees and state machines in the past.

Reflecting on this conversation, I suppose there really isn't any reason a behavior tree couldn't use fuzzy logic, based on what I know; perhaps my focus should be less on new AI structures and more on learning and applying fuzzy logic. Thanks for your response!

A different common option is to have a bunch of utility functions.  Pass your input to all the different potential actions and score them.  Instead of always choosing the topmost score, you might randomly select from among all those within 10% of the top score (or some other threshold).

That way you still get the benefits of the predictable state machine, and you still get characters following the most probable actions, but they can appear to make a choice between the various most likely options.

I just want to jump in here and say that a utility-based AI is not the same as fuzzy logic, which is a very specific thing.

Utility systems for AI are basically about scoring potential actions and picking the activity based on that scoring. The UE4 behavior tree system isn't ideally suited for this, but you could have a Service that performs the evaluation and picks the relevant activity to execute, storing that choice in the blackboard, and the tree could just have a big Selector node where each child node has a conditional decorator to check if it is the chosen activity, and obviously only execute if so. Below that node could be whatever BT-based nodes are necessary to carry out that activity.

A fuzzy logic system would typically be taking a bunch of continuous or discrete input values, evaluating a bunch of fuzzy conditions to translate that to fuzzy set membership, combining those results, and then defuzzifying them to get a bunch of usable output values. You could then pipe those values into whatever algorithm you like - including a utility system! - but usually it's just used as a way to get a few continuous values out for direct use, such as motor speed or wave amplitude. Fuzzy logic is not actually that widely used.

Have you considered goal oriented action planning instead of a behaviour tree?

For example: https://gamedevelopment.tutsplus.com/tutorials/goal-oriented-action-planning-for-a-smarter-ai--cms-20793

its relatively easy to implement, but isn’t a standard option in ue4 and will have to be implemented from scratch. I’m sure you’ll be able to find someone else has already done it though.

personally I’ve found goal oriented action planning to appear to make smarter decisions with less code, YMMV...

Advertisement

Thank you all so much for your help, explanations, suggestions, and resources!

Frob, that seems like an excellent option that would be doable for me. I don't believe I have worked with utility functions yet, so I will definitely take a look at that!

Kylotan, thank you for your detailed description of utility systems and fuzzy logic; these are two areas I am very new to, and your explanation was more helpful than I can describe. Your suggestion of how the behavior tree could be used to achieve this effect seems great for my application. I will give that a try!

Brain, I had seen a couple sources on goal oriented action planning, but none as thorough as the link you provided. This definitely looks like a good option. Reading through the tutorial you've provided, I believe I could get a similar effect from Unreal's behavior tree system, simply working in a kind of reverse fashion. In other words, instead of working from the simplest action working forward, work from the most complex action going backwards.

Thanks again; this has been extremely helpful!

I can't really speak on this from a game development perspective, but i can speak from a robotics and automation perspective. 

I have previously worked with fuzzy logic with robotics before, but I remember extremely well the pain and agony that was getting the fuzzy rules right. Myself and another student at the engineering school I attended spent two weeks configuring fuzzy rules for a robot to navigate a maze and then, at a later time, recall the shortest route it found. The issue wasn't getting fuzzy logic to work, but rather the difficulty was getting the rules fine tuned and getting defects/bugs worked out.

As far as a game AI is concerned, and considering my experience with fuzzy logic, I can't imagine it would make for a good AI on its own; it would need some other data structure backing it up. I can see where, when combined with a traditional decision tree, how it would create the illusion of an AI having "moods," aka defining behaviors such as "happy," "calm," or "pissed off." But, as a previous posted has posted, this can also be accomplished with clever use of enums. 

If Unreal doesn't have libraries for fuzzy logic, there are plenty of C++ libraries that can be imported to supplement Unreal's decision trees.

This topic is closed to new replies.

Advertisement