Hellow~
So for a bit of context: i'm currently working on a RTS (way above may league) which already has a level editor and a node grid which maps the terrain, i previously make a navigation system with A* as explainned by Sebastian Lague in his tutorial series about the topic, but then i run into a problem when running with multiple units (not the point here: but never manage to find each unit cluster within the selection), so i change it into a navmesh mapping which if made dynamic by assigning navmesh obstacles to the unwalkable nodes (the frame after the creation of the node grid)
Now i want to use the node grid basically to check if the target node and the start node share the same node cluster. But here is the thing: i can't assign the needed index to the nodes as i expected.
I've been trying adapting code from this post, but didn't quite make it. Now i have this one, which i think could achieve something but still gets me a invalid operation exception:
public const int UNWALKABLE_ISLAND = 999;
public static void SetIslands(ref WorldGrid _worldGrid) {
int width = _worldGrid.nodeGrid.GetLength(0);
int height = _worldGrid.nodeGrid.GetLength(1);
bool[,] visited = new bool[width, height];
int clusterCount = 0;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++)
{
if (visited[x, y]) { continue; } else {
List<Node> cluster = new List<Node>() {
_worldGrid.nodeGrid[x, y]
};
foreach (var node in cluster) {
if (node.isWalkable)
{
visited[node.X, node.Y] = true;
node.SetIslandIndex(clusterCount);
cluster.AddRange(_worldGrid.GetNeighbours8D(node));
}
else
{
cluster.Remove(node);
}
}
clusterCount++;
}
}
}
}
The error:
InvalidOperationException: Collection was modified; enumeration operation may not execute. System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource resource) (at<437ba245d8404787b9fbab9b439ac908>:0) System.Collections.Generic.List
1+Enumerator[T].MoveNextRare() (at<437ba245d8404787b9fbab9b439ac908>:0) System.Collections.Generic.List
1+Enumerator[T].MoveNext() (at<437ba245d8404787b9fbab9b439ac908>:0) Pathfinding.SetIslands (WorldGrid& _worldGrid) (at Assets/Pathfinding.cs: 25) WorldGrid.CreateNodeGrid() (at Assets/WorldGrid:80) WorldGrid+d_12.MoveNext() (at Assets/WorldGrid.cs:42) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, Sustem.IntPtr returnValueAddress) (at<437ba245d8404787b9fbab9b439ac908>:0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
My node class contains an int that should hold the cluster index, which will be using for the request check. (the code its based from this youtube video)
Right now i'm trying to understand the spectral clustering stuff, i've been told it could help.
I hope you can help an animator in need with some pointers.
Cheers :3
*Oh!, I also tried reading the nav agent path end coordinate for comparison, but it ended up becoming a huge mess for me.
foreach (var node in cluster) {
. Line 80 in WorldGrid.cs is the calling of the methodPathfinding.SetIslands(ref Instance);
\$\endgroup\$foreach
occurs nowhere in the code you're modifying. \$\endgroup\$