Page 1 of 1

How to properly cancel (make inactive) the current node and all children?

Posted: Tue May 31, 2022 10:18 am
by EVG
How to properly cancel (make inactive) the current node and all children?
Right now I'm trying to do it like this:
StopChecking();
questNode.SetState(QuestNodeState.Active);
for (int i = 0; i < questNode.childList.Count; i++)
{
questNode.childList.SetState(QuestNodeState.Inactive);
questNode.childList.conditionSet.StopChecking();
questNode.childList.SetConditionChecking(false);
}
But the problem is that when canceling child elements, they still continue to check the conditions. That is, the node, if the conditions are met, can go to the True state, even if it is inactive.
The video shows that the canceled node was still executed if its conditions were met.

Re: How to properly cancel (make inactive) the current node and all children?

Posted: Tue May 31, 2022 10:46 am
by Tony Li
Hi,

Try setting the quest node states first, starting with the children, then the quest state (if desired). You don't have to call StopChecking() manually. To set all nodes inactive.

Code: Select all

foreach (QuestNode child in questNode.childList)
{
    child.SetState(QuestNodeState.Inactive);
}
questNode.SetState(QuestNodeState.Inactive);
If you want to set everything active all the way down the tree, not just the node's direct children, you can use recursion:

Code: Select all

var visited = new List<QuestNode>(); // Keep track of which nodes we've already done, in case nodes link circularly.
ResetNode(questNode, visited);

void ResetNode(QuestNode questNode, List<QuestNode> visited)
{
    if (questNode == null || visted.Contains(questNode)) return;
    visisted.Add(questNode);
    foreach (QuestNode child in questNode.childList)
    {
        ResetNode(child, visited);
    }
    questNode.SetState(QuestNodeState.Inactive);
}

Re: How to properly cancel (make inactive) the current node and all children?

Posted: Tue May 31, 2022 10:56 am
by EVG
If the node was previously active, then when it is turned off, it is still executed when the condition is true.

Re: How to properly cancel (make inactive) the current node and all children?

Posted: Tue May 31, 2022 11:09 am
by Tony Li
Can you send a reproduction project to tony (at) pixelcrushers.com?

Re: How to properly cancel (make inactive) the current node and all children?

Posted: Tue May 31, 2022 11:16 am
by EVG
The problem turned out to be in my custom condition on the child node, it seems to have been fixed. Thank you again for your help!

Re: How to properly cancel (make inactive) the current node and all children?

Posted: Tue May 31, 2022 12:04 pm
by Tony Li
Happy to help! I'm glad you found the issue.