- A* version: [5.3.3]
- Unity version: [6000.2.10f1]
I use Layered Grid Graph and bake the navmesh for my room and save it. Transform of my room during the bake is on the origin of the world. In-game, the position and rotation of my room changes, so when I load my baked navmesh, I have to reposition the nodes to fit the room. I do so using this approach:
public void LoadGraph(TextAsset graph, Transform roomTransform)
{
if (graph == null || roomTransform == null) return;
AstarPath.active.data.DeserializeGraphs(graph.bytes);
LayerGridGraph gridGraph = AstarPath.active.data.layerGridGraph;
AstarPath.active.AddWorkItem(new AstarWorkItem(ctx =>
{
Matrix4x4 matrix = Matrix4x4.TRS(
roomTransform.position,
roomTransform.rotation,
Vector3.one
);
gridGraph.GetNodes(node =>
{
Vector3 localPos = (Vector3)node.position;
Vector3 worldPos = matrix.MultiplyPoint3x4(localPos);
node.position = (Int3)worldPos;
node.SetConnectivityDirty();
});
gridGraph.RecalculateAllConnections();
gridGraph.showNodeConnections = true;
AstarPath.active.data.UpdateShortcuts();
}));
}
The following image shows both the original position of baked navmesh(left) and position updated one(right).
The node connection lines on the right show that repositioning of nodes is correct. The problem is that my agents cannot walk on them. I may even have used some unnecessary code hoping they would solve the problem.
What am i missing here?
What is the right way to use a baked navmesh on a repositioned room?
