public void WaypointSystemChangedCallback() { WaypointManager wg = GameObject.Find("WaypointManager").GetComponent <WaypointManager>(); var sources = wg.pathNodes; int startIndex = -1; int endIndex = -1; if (actualStartNode == null || !actualStartNode.nodeValid) { startIndex = PathfindingManager.Closest(sources, startNodePosition); actualStartNode = sources[startIndex]; } if (actualTargetNode == null || !actualTargetNode.nodeValid) { endIndex = PathfindingManager.Closest(sources, endNodePosition); actualTargetNode = sources[endIndex]; } bool found = false; if (path != null) { //foreach (PathNode pn in path) for (int i = 0; i < path.Count; i++) { PathNode pn = path[i]; if (pn == null || !pn.nodeEnabled || !pn.nodeValid) { found = true; break; } } if (found) { path.Clear(); } } }