Hello!
I want to export the graph using a script, and then also use tilemap tile data to tag certain nodes. However, the tags do not seem to work. My non-flying enemies walk right through the water (set to not traverse water in Seeker
component) and the debug does not color the water a different color (I have it set to color tags in debug settings).
I have ExportAStarGraphTool.cs
which basically just exports the graph data to a specific folder.
public static void ExportAStarGraph() {
AstarPath.FindAstarPath();
Selection.SetActiveObjectWithContext(AstarPath.active, AstarPath.active.gameObject);
string assetPath = GetGraphPath();
SerializeSettings serializationSettings = SerializeSettings.Settings;
serializationSettings.nodes = true;
AstarPath.active.Scan();
byte[] data = AstarPath.active.data.SerializeGraphs(serializationSettings, out _);
AstarPath.active.FlushWorkItems();
string directory = Path.GetDirectoryName(assetPath);
AstarSerializer.SaveToFile(assetPath, data);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
And GraphUpdateSceneTilemap.cs
which I use to tag Water and Pit nodes:
[RequireComponent(typeof(Tilemap))]
public class GraphUpdateSceneTilemap : GraphUpdateScene {
public override void OnPostScan() {
applyOnStart = false;
Tilemap tilemap = GetComponent<Tilemap>();
foreach (Vector3Int position in tilemap.cellBounds.allPositionsWithin) {
TileBase tile = tilemap.GetTile(position);
if (tile != null && (tile as BaseTile).AStarTag != AStarTag.None) {
Bounds bounds = new Bounds(position, Vector2.one);
GraphUpdateObject guo = new GraphUpdateObject(bounds) {
modifyWalkability = false,
setWalkability = false,
addPenalty = 0,
updatePhysics = false,
updateErosion = false,
resetPenaltyOnPhysics = false,
modifyTag = true,
setTag = (int) (tile as BaseTile).AStarTag
};
AstarPath.active.UpdateGraphs(guo);
}
}
}
}
Is the right approach? Is there anything that you notice I am doing incorrectly?