I can't scan my terrain

Everytime I scan my terrain it will become null in the next frame, I could only check this by pausing the game and scanning

What becomes null exactly?
Screenshots?

Well, it doesn’t actually become null. If I tick Show Graph, and I scan the terrain without pause enabled it no grid shows at all, but if I tick pause so that the game is paused, I can then see the grid when I scan.
Screenshots:
Before:


& after:

Both are taken after a scan, but only the one that’s paused shows a grid.

Should I try to reinstall the plugin?

EDIT: Had no effect on the problem :stuck_out_tongue:

I found out that there is a grid, it is just not showing and when using the procedural gridmover, the game seems to be lagging every few meters I walk. Could this have something to do with my grid not always filling out my entire terrain.

Hi

Your images are not showing, they seem to be private. I get a 403 when I try to access them.

During the same frame as the graph is updated, the graph will not be visible (the graph might not be in a consistent state during that time, so it’s best just to hide it). Since the procedural grid mover updates the graph a lot, it will also hide the graph a lot.

The procedural grid mover does have quite a lot of overhead since calculating the graph is not cheap. If you can, reduce the size/resolution of your grid graph to lower this overhead. You can also try to increase the update distance on the procedural grid mover. If you change it to a higher value, it will update less often, but each update will be slightly slower, if you change it to a lower value, it will update more often, but each update will be slightly faster (there is still some overhead to just updating the graph, so it is usually not optimal to have a really small update distance).

No matter what I change the sizes and update distance to it always gives the same result. With the grid not being visible/usable. I have updated the photos above.

Hi

A 300300 grid is a bit large to be using the ProceduralGridMover on so I guess that’s why you have so much lag. I wouldn’t go much higher than 100100 with it to avoid lag.

Try to set the update distance to infinity (or some huge value) and see what happens. The grid shouldn’t update then and you should be able to see it in the editor.

PS: Also know that having Show Graphs enabled will severely reduce your framerate since it actually has to draw that graph every frame, and that is not exactly cheap since you have 90000 nodes in it.

I could only get it down to 250*250 without losing the ability to see the objects. But it didn’t fix my problem, the grid still only shows when the game is paused. NOTE: If I use this script it works fine, but it isn’t as optimized, because the ProceduralGridMover just moves the already scanned nodes to the new location:

`#pragma strict

private var graph : GridGraph;
private var target : Transform;
var UpdateDist : int;

private var DelayInUnitsX : int;
private var DelayInUnitsY : int;
private var terrainSize : int;

private var qLevel : int;

function Start () {
ScanPos = transform.position;
graph = AstarPath.active.astarData.gridGraph;
terrainSize = GameObject.Find(“Terrain Generator”).GetComponent(PT).terrainSize;
}

var ScanPos : Vector3;

function Update () {
if (Vector3.Distance(transform.position, ScanPos) > UpdateDist) {
Debug.Log(“Updating AI Grid”);
ScanPos = transform.position;
UpdateNodes();
}
}

function UpdateNodes() {
var time = Time.realtimeSinceStartup;

if (graph == null) {return;}

qLevel = QualitySettings.GetQualityLevel();
if (qLevel <= 2) {
	DelayInUnitsY = 300;
	DelayInUnitsX = 150;
} else {
	DelayInUnitsY = 100;
	DelayInUnitsX = 300;
}

var width = graph.width;
var depth = graph.depth;
var nodes : GridNode[] = graph.nodes;

graph.center = ScanPos;
graph.GenerateMatrix();

for (var z = 0; z < depth; z++ ) {
	for (var x = 0; x < width; x++ ) {
		var node = nodes[z*width+x];
		graph.UpdateNodePositionCollision(node, x, z, false);
		if (z % DelayInUnitsY == 0 && x % DelayInUnitsX == 0) {
			yield;
		}
	}
}

for (var z1 = 0; z1 < depth; z1++ ) {
	for (var x1 = 0; x1 < width; x1++ ) {
		graph.CalculateConnections(nodes, x1, z1, nodes[z1*width+x1]);
		if (z1 % DelayInUnitsY == 0 && x1 % DelayInUnitsX == 0) {
			yield;
		}
	}
}

AstarPath.active.FloodFill();

}`

NOTE: It seems like the white border isn’t even rendered when the game isn’t paused.

EDIT: I found out that the terrain isn’t setting the correct center and is then updating constantly. Which causes the graph to be unrenderable.

Hi

Seems like you found the bug that was causing it not to work (in another thread).
Is everything working as you want now?

Yeah, it is working fine now :slight_smile: