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.
How to properly cancel (make inactive) the current node and all children?
Re: How to properly cancel (make inactive) the current node and all children?
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.
If you want to set everything active all the way down the tree, not just the node's direct children, you can use recursion:
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);
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?
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?
Can you send a reproduction project to tony (at) pixelcrushers.com?
Re: How to properly cancel (make inactive) the current node and all children?
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?
Happy to help! I'm glad you found the issue.