AI Components

I’ve been working on a few components that add features to Blueprint that could be useful for creating AI. So I thought I would post about them to see if there would be any interest in them. None of them are finished yet, but hopefully by time they are, the Market place will allow C++ plugins.

Rule based Component
The first component is a Rule based one. The idea of it, is to allow the easy creation of Rules in Blueprint that will trigger when preconditions for that rule are met. This works by creating a Blueprint based on a the base RuleClass. Then inside that blueprint’s event graph, you can add as many “rule nodes” as you want, and link each rule node to a set of precondition nodes. The rule nodes are a Composite type of node, so you actually define the nodes that will trigger inside the rule node (like a macro). While the precondition nodes can be either of a composite type, for a custom test function, or more simple nodes that will just check if a bool value is true or false. As I’m using a custom Blueprint compiler, the rule nodes (and their preconditions) don’t have to be linked to each other, or to any event. The precondition nodes just have to be linked to the rule node that they are for. The compiler finds the rule nodes and then works out how to handle them and their preconditions.

Once the Rule blueprint has been created, you can then attach it to any other blueprint and call the ProcessRules function on it, which will check the preconditions and trigger any rule that matches them.

Logic Component
The next component is a Logic component, that allows Prolog type queries to be used in Blueprint. So you can define a set of facts (and add to them or change them at any time), then run queries against those facts. At the moment I still need to do some work on making the Blueprint API easier to use.

So the following image shows a query that is trying to find all the “people” who are a friend of one of Mark’s brothers. So the facts could include “Mark has Brother John”, “Mark has Brother Eric”, “John has Friend Josh”, “John has Friend Lisa” , “Eric has Friend David”, “Eric has Friend Mike”. Then the result of our query would return a list containing “Josh, Lisa, David and Mike.”. As we have to build the query as a two step process, we would also have a list containing all of Mark’s brothers.

So in the above image, we first call the Begin New Logic Query function, that basically sets everything up for a new query to be defined. Then we add the first step to the query which is to find the brothers of Mark. In this example we hard code “Mark” into the blueprint but normally would use some variable so we could use the same query on other “people”. The logicData items are reference variables. So in our example, the brothers would be stored in the “Logic Data” variable. Then for the new step in our query we use that “Logic Data” variable (that will contain a list of Mark’s brothers) and find all the friends of the people in that list. The result of this is stored in the “Logic Data 2” variable. Then in this example we just print out the list of friends from the “Logic Data 2” variable.

In technical terms neither of the lists actually contain anything until we fetch the result of the query. As all those two “Find Relationship” nodes did, was to build a query, but didn’t actually run that query. So there is various things we could do with a query result. The simplest would be just to check that there was a matching result. So a very simple query would be just to check if Mark was male , and then if there is a result we know he is. Or we could step through the result, one item at a time. Or as in the example above we could get the whole result in one go and do something with it.

Statemachine Component
The last component that I am currently working on, is a State machine one. The basic idea is to allow state machines to be created in a similar way as they are in the Animation Blueprints, but to allow them in non animation blueprints (they of course wouldn’t be just for dealing with animations). While UE4 has behaviour trees built in, I have found in some cases, I just want a simple state machine. With this component I have finished the basic functionality but need to work on a custom Blueprint editor so that the state nodes don’t need to be connected to each other via a visible pin.

A state machine outside animation blueprints would indeed be useful. Is this a plugin or source code?

It is a plugin, unless I hit any problems that don’t work in a plugin, but I don’t expect there to be any. Although I plan to provide the source code for it as well.