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

Announcements, support questions, and discussion for Quest Machine.
Post Reply
EVG
Posts: 27
Joined: Sun Jul 04, 2021 4:55 pm

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

Post 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.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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);
}
EVG
Posts: 27
Joined: Sun Jul 04, 2021 4:55 pm

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

Post by EVG »

If the node was previously active, then when it is turned off, it is still executed when the condition is true.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Can you send a reproduction project to tony (at) pixelcrushers.com?
EVG
Posts: 27
Joined: Sun Jul 04, 2021 4:55 pm

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

Post 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!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Happy to help! I'm glad you found the issue.
Post Reply