Creating Custom Nodes

If you are working on a game made with Corgi Engine, chances are you are going to create new AI Decisions and AI Actions: the AI Brain Graph is completely extensible, so you can create your own nodes.

Basically, each node acts as a component generator for the corresponding action or decision, so you'll just have to pass the correct attributes.

Creating AI Action Nodes

To create your own action nodes, you will have to extend the AIActionNode class and override a single method, called AddActionComponent: this component returns an instance of the Corgi AIAction you want to add with this node.

As an example, please take a look at the AIActionJumpNode that corresponds to the AIActionJump for the Corgi Engine:

using MoreMountains.CorgiEngine;
using MoreMountains.Tools;
using UnityEngine;

namespace TheBitCave.CorgiExensions.AI
{
    /// <summary>
    /// A node representing a Corgi <see cref="MoreMountains.CorgiEngine.AIActionJump"/> action.
    /// </summary>
    [CreateNodeMenu("AI/Action/Jump")]
    public class AIActionJumpNode : AIActionNode
    {
        public int numberOfJumps = 1;

        public override AIAction AddActionComponent(GameObject go)
        {
            var action = go.AddComponent<AIActionJump>();
            action.Label = label;
            action.NumberOfJumps = numberOfJumps;
            return action;
        }
    }
}

Please note the [CreateNodeMenu("AI/Action/Jump")] that adds this node to the graph contextual menu.

Creating AI Decision Nodes

To create your own decision nodes, you will have to extend the AIDecisionNode class and override a single method, called AddDecisionComponent: this component returns an instance of the Corgi (or TopDown Engine) AIDecision you want to add with this node.

As an example, please take a look at the AIDecisionHitNode that corresponds to the AIDecisionHit :

using UnityEngine;
using MoreMountains.CorgiEngine;
using MoreMountains.Tools;

namespace TheBitCave.CorgiExensions.AI
{
    /// <summary>
    /// A node representing a Corgi <see cref="MoreMountains.CorgiEngine.AIDecisionHit"/> decision.
    /// </summary>
    [CreateNodeMenu("AI/Decision/Hit")]
    public class AIDecisionHitNode : AIDecisionNode
    {
        public int numberOfHits = 1;

        public override AIDecision AddDecisionComponent(GameObject go)
        {
            var decision = go.AddComponent<AIDecisionHit>();
            decision.Label = label;
            decision.NumberOfHits = numberOfHits;
            return decision;
        }
    }
}

Please note the [CreateNodeMenu("AI/Decision/Hit")] that adds this node to the graph contextual menu.

Last updated