News Forums RAIN General Discussion and Troubleshooting Custom Decision Node?

This topic contains 11 replies, has 5 voices, and was last updated by  prime 7 months, 4 weeks ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #33450

    Yuewah Chan
    Participant

    any code example with explanation for the custom decision node in v2.1.4 ?

    #33452

    prime
    Keymaster

    We’ll put something out as soon as we can.

    Generally you use the node just like a custom action. The difference is that the custom decision can have child nodes. The default implementation of a custom decision is a Sequencer node. By changing the logic and processing of child nodes, you can make the Decision node work however you like.

    Here’s an example of creating a node that runs like a sequencer, but returns the inverse of the normal return value. (e.g., if the Inverter has a single node that runs and returns true, the Inverter would return false instead.)

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    [RAINDecision("Inverter")]
    public class Inverter : RAINDecision
    {
        private int _lastRunning = 0;
        public override void Start(AI ai)
        {
            base.Start(ai);
            _lastRunning = 0;
        }
        public override ActionResult Execute(AI ai)
        {
            ActionResult tResult = ActionResult.SUCCESS;
            for (; _lastRunning < _children.Count; _lastRunning++)
            {
                tResult = _children[_lastRunning].Run(ai);
                if (tResult != ActionResult.SUCCESS)
                    break;
            }
            if (tResult == ActionResult.SUCCESS)
                return ActionResult.FAILURE;
            if (tResult == ActionResult.FAILURE)
                return ActionResult.SUCCESS;
            return tResult;
        }
        public override void Stop(AI ai)
        {
            base.Stop(ai);
        }
    }
    #33492

    Iuxeayor
    Participant

    This question is only semi-related:
    Are we able to create custom Action Nodes, as well? I am curious if I can extend the “Move” node so that I can move along the object’s own forward vector while attempting to move toward a Navigation target. Essentially, this creates a “Banking” effect. I would rather do this than a custom script if possible. ;>

    • This reply was modified 1 year, 2 months ago by  Iuxeayor.
    #33501

    prime
    Keymaster

    Sure. custom action nodes have been in RAIN for as long as I can remember. I think we’ve even posted extensions to the move node here on the forums somewhere

    #33560

    Yuewah Chan
    Participant

    If I create custom decision class in BTEditor, it does not create the custom decision script file for me.

    #33562

    Yuewah Chan
    Participant

    Is it possible that Custom Decision Node (RAINDecision) support Expression property? Just like RAINAction supports Expression.

    #33573

    prime
    Keymaster

    Custom decision script file should be generated… I’ve tested it without issue.

    Yes, we’ll make the change so custom decisions properly support Expressions. Should have been that way to begin with - just an oversight.

    #35008

    jayx2thez
    Participant

    Hello,

    I want to try and get my custom decision node to go to a waypoint only if a variable I detect in a dialogue system plugin fro unity is true.

    Here is what I have:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using PixelCrushers.DialogueSystem;
    [RAINDecision]
    public class convo : RAINDecision
    {
        private int _lastRunning = 0;
        public override void Start(RAIN.Core.AI ai)
        {
            base.Start(ai);
            _lastRunning = 0;
        }
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
    		ActionResult tResult = ActionResult.FAILURE;
    		if (DialogueLua.GetVariable ("end").AsBool) {
    				tResult = ActionResult.SUCCESS;
    		}
    		for (; _lastRunning < _children.Count; _lastRunning++) {
    			tResult = _children [_lastRunning].Run (ai);
    			if (tResult != ActionResult.SUCCESS)
    		break;
    		}
    		return tResult;
        }
        public override void Stop(RAIN.Core.AI ai)
        {
            base.Stop(ai);
        }
    }

    Currently, as soon as I start the level, the move and animate child nodes immediately trigger and the NPC goes running. I want to have them conditionally trigger based on the value from the conversation system DialogueLua.GetVariable (“end”).AsBool.

    This is my first post, so please excuse any noob mistakes I might be making, any advice and assistance would be greatly appreciated.

    #35040

    prime
    Keymaster

    Real quick clarification on Decisions vs. Actions. Decision nodes are typically container nodes that define how a set of child nodes are processed. Examples are Sequencer, Selector, and Parallel. Action nodes typically don’t have children and either perform some task, or evaluate some condition. So in this case I suspect you want a RAINAction, not a RAINDecision. You could use the result (SUCCESS/FAILURE) as your condition for taking action, much like an Expression node is used.

    So your code becomes:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using PixelCrushers.DialogueSystem;
    [RAINAction("Is Dialog End")]
    public class IsDialogEnd: RAINAction
    {
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
            return (DialogueLua.GetVariable("end").AsBool) ? ActionResult.SUCCESS : ActionResult.FAILURE;
        }
    }
    #35041

    prime
    Keymaster

    Next, you will probably want to use that in a SELECTOR:

    SELECTOR
    -SEQUENCER
    —-CUSTOMACTION //Your IsDialogEnd
    —-MOVE(waypoint) //Your move to waypoint action
    -SOME OTHER BEHAVIOR

    or, if you are simply waiting for a dialog to finish, then

    SEQUENCER
    — CUSTOMACTION (Repeat until success) //Your IsDialogEnd
    — MOVE(waypoint) //Your move to waypoint action

    #37814

    CAS_Kicks
    Participant

    I’m trying to make a switch node.
    I’m hoping to set it up like the random node only you pass a memory variable to the switch node, then instead of weights, you provide case: values in each child node.
    Is this possible? Is there an already existing method?
    Right now I use a selector, then children constraint nodes of memoryValue == case

    Thanks!

    #37829

    prime
    Keymaster

    That’s usually done like this:

    SELECTOR
    -SEQUENCER
    —- EXPRESSION (var == “option1″)
    —- OPTION 1 ACTIONS
    -SEQUENCER
    —- EXPRESSION (var == “option1″)
    —- OPTION 2 ACTIONS
    etc.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.