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.
-
AuthorPosts
-
October 21, 2022 at 8:14 am #33450
any code example with explanation for the custom decision node in v2.1.4 ?
October 21, 2022 at 5:28 pm #33452We’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); } }
October 24, 2022 at 10:26 am #33492This 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.
October 24, 2022 at 10:57 am #33501Sure. 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
October 27, 2022 at 10:29 pm #33560If I create custom decision class in BTEditor, it does not create the custom decision script file for me.
October 27, 2022 at 11:17 pm #33562Is it possible that Custom Decision Node (RAINDecision) support Expression property? Just like RAINAction supports Expression.
October 28, 2022 at 7:31 am #33573Custom 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.
January 6, 2023 at 5:05 pm #35008Hello,
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.
January 11, 2023 at 8:06 am #35040Real 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; } }
January 11, 2023 at 8:10 am #35041Next, you will probably want to use that in a SELECTOR:
SELECTOR
-SEQUENCER
—-CUSTOMACTION //Your IsDialogEnd
—-MOVE(waypoint) //Your move to waypoint action
-SOME OTHER BEHAVIORor, if you are simply waiting for a dialog to finish, then
SEQUENCER
— CUSTOMACTION (Repeat until success) //Your IsDialogEnd
— MOVE(waypoint) //Your move to waypoint actionMay 3, 2022 at 2:50 pm #37814I’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 == caseThanks!
May 5, 2022 at 5:38 am #37829That’s usually done like this:
SELECTOR
-SEQUENCER
—- EXPRESSION (var == “option1″)
—- OPTION 1 ACTIONS
-SEQUENCER
—- EXPRESSION (var == “option1″)
—- OPTION 2 ACTIONS
etc. -
AuthorPosts
You must be logged in to reply to this topic.