Forums › 💬 NodeCanvas › ⚙️ Support › BT sequence of actions that starts&restarts when receiving a specific Event › Reply To: BT sequence of actions that starts&restarts when receiving a specific Event
I tried making the Reset node, but it’s not working as expected. This is the code that I have:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; namespace NodeCanvas.BehaviourTrees { [Name("Reset")] [Category("Decorators")] [Description("Reset the child node if the condition is true while running. Always runs the decorated child node and returns its status")] [Icon("Resetter")] public class Resetter : BTDecorator, ITaskAssignable<ConditionTask> { [SerializeField] private ConditionTask _condition; public ConditionTask condition { get { return _condition; } set { _condition = value; } } public Task task { get { return condition; } set { condition = (ConditionTask)value; } } protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; if (condition != null && status == Status.Running && condition.CheckCondition(agent, blackboard)) decoratedConnection.Reset(); return decoratedConnection.Execute(agent, blackboard); } } } |
See the attached image for my current BT-test setup. The root node is this new Reset node that I made.
The Log actions execute normally when I fire the very first event. The log action tasks also get interrupted and restarted as intended if I fire events before the actions finish.
However, if I wait for the action node to finish, the next event will trigger only the “On” message, and interrupt the action node immediately, or so it seems. Is there anything wrong with my code?
