If the last node in a dialogue thread is a blue “Player Speaking” node (with no children), there’s an exception raised in PlayerConversant.Next()
because there are no AI children nodes.
Unfortunately Random.Range(0, 0)
returns 0, even though the function documentation says that it should never return the exclusive end of the range (perhaps it should throw an exception instead?). So using the length of the child array as the endpoint results in attempting to address index 0 of a 0-length array.
I fixed this by first checking for no children, and if there aren’t any, calling Quit()
instead. This seems to work nicely - you get the last choice of dialogue, you pick one, and then the dialogue panel is hidden.
if (childNodes.Length > 0)
{
currentNode = childNodes[Random.Range(0, childNodes.Length)];
}
else
{
Quit();
}