- Home /
Unity crash when I add a Vector2 to a List
Hi, I'm creating a function in my script that, given a GameObject's position and an obstacle's box collider2D, it should return the "nodes", that are 4 point with a certain distance from the 4 corners of the box collider, that are reachable from the GameObjects (In this case GameObject is an Ai). After getting nodes position (with "GetNodes"), I check if every node is reachable (nodes are always 4, as the number of the corners of a rectangle); if the node is not disabled, I create a Raycast in order to verify if the node is reachable, and, if it's reachable, I go to Add it to a list containing all reachable nodes. All Lists are declared at the beginning of the script, in order to be used by more functions.
The problem is that when this function is called, Unity crash, blocking the editor and I'm obliged to forcefully close the program. Trying to modify the code, i discovered that the problem is adding the position to the list with all reachable nodes. Unity doesn't send any error message, and I don't know what could be wrong.
void FindReachableNodes(Vector2 startPos, BoxCollider2D obsCollider) //obs = obstacle
{
Vector2[] nodes = Nav.GetNodes(obsCollider, AiCollider, offset); //returns position of 4 nodes
ReachableNodes.Clear();
int i;
for (i = 0; i < 4; i++)
{
if (!DisabledNodes.Contains(nodes[i]))
{
ShootRaycast(startPos, nodes[i]);
if (!Hit1 && !Hit2)
{
ReachableNodes.Add(nodes[i]); //This line makes unity crash
}
}
}
}