GraphUpdateScene 'points array' - Use Mesh?

I was wondering if perhaps there was already a work-around for this, but: Can a mesh be substituted for the ‘points array’ in a GraphUpdateScene script?

I’m finding that when creating area for ‘complex’ geometry area (like a terrain contour), a change in that terrain means I have to completely re-create the GraphUpdateScene point array (adding or subtracting 1 point basically means I have to re-create the whole thing), so I was wondering if, like a NavmeshCut script, I could instead use pre-made mesh (which is also much more accurate / I could re-use the mesh I already made the the Cut script)?

I’m interested in using a NavmeshCut script with “IsDual” along with a GraphUpdateScene that modifies the node penalty, but since I have to re-make all the point arrays each time and area / agent changes shape, for the moment I’m just using ‘cut’ and hoping my agents don’t wander out of their safe areas.

Hi

Sorry, there is no support for that at the moment.
Note however that you can change the positions of the points after you have placed them the first time by simply selecting them in the scene view. You can also open the “Points” list in the inspector and duplicate any element to get a new point (you can duplicate array elements by right clicking on them and selecting duplicate).

1 Like

You can if you want make a script that uses the navmesh cut contour by calling the NavmeshCut.GetCountour method. It will return a list of contours (navmesh cuts can contain multiple, you likely just want to use the first one) with the type ClipperLib.IntPoint, you can convert IntPoint to Vector3 by calling the NavmeshCut.IntPointToV3 function.

1 Like

Did not realize the options with Right Click, great to know. Also, I’m sure I’m over simplifying this (because I don’t know all the considerations the GraphUpdateScene makes), but if you took a mesh that is already ‘safe’ in terms of its construction, could you not ‘feed’ those vertices points into the array? I don’t know if the order would be preserved (I guess that would be a huge problem if there was no way to order them before insertion), just me thinking out loud.

-Looking at your second message:
Interesting, I’ll keep pursuing that approach as well.

Yeah, you cannot just feed a mesh’s vertices to it, you would need to extract the contours like the navmesh cut script does.

Made a basic test version using ExecuteInEditMode, seems to work (not sure if I need the Claim and Release methods…do I?). Thank you very much for the help (I’m going to bed).

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Pathfinding;
using Pathfinding.ClipperLib;

[ExecuteInEditMode]
public class Pathfinding_GUSExtender : MonoBehaviour {
//extender to get NMC counturs into the GUS point array
//

[Header ("Update: ")]
public bool updateThisScript = false;

[Header ("Refs: ")]
public NavmeshCut nmc;
public GraphUpdateScene gus;

private List<List<IntPoint>> ip = new List<List<IntPoint>>();
private Vector3[] tempArray;


void Update()
{
 	updateThisScript = false;

	Debug.Log("update is updating 1...");

	if(nmc != null && gus != null)
	{
		Debug.Log("update is updating 2...");

		//don't seem to be needed, ask if needed:
		//ip = Pathfinding.Util.ListPool<List<Pathfinding.ClipperLib.IntPoint>>.Claim();

		nmc.GetContour(ip);

		//List<Pathfinding.ClipperLib.IntPoint> cont = ip[0];
		tempArray = new Vector3[ip[0].Count];

		//according to him, we probably only want the 1st countour
		for(int counter = 0; counter < ip[0].Count; counter++)
		{
			Debug.Log("working");
			tempArray[counter] = NavmeshCut.IntPointToV3(ip[0][counter]);
		}

		gus.points = tempArray;

		//don't seem to be needed, ask if needed:
		//Pathfinding.Util.ListPool<List<Pathfinding.ClipperLib.IntPoint>>.Release(ip);
	}
}

}`

Nice that it’s working.

If you don’t clear the list the GetContour method will just keep adding contours to the “ip” list every time you call the method. ListPool is used to reuse lists to avoid excessive allocations, you can remove it if you want (see documentation page on pooling if you want to know more).