NavMeshPlus
NavMeshPlus copied to clipboard
The "Bake Runtime" system is tiring for mobile devices...?
I did exactly what you wrote in the "How To" section for the 2D game and it worked. I used BuildNavMesh in the lateupdate function of the "NavMesh" object to update the walkable area after the destroyed objects (Tile) were destroyed during the game and it worked again. Paths are now updated while the game is running. Thank you so much.
What I'm wondering is how tiring this system can be for mobile devices. Issues such as heating the device immediately... What do you think?
Hello @GugaGuga9
I don't have ability to test such case. But in general:
- Call
Surface2D.BuildNavMeshAsync()
only once - Don't call
NavMeshBuilder.UpdateNavMeshDataAsync
every frame, only when needed - Use cache to provide new sources into
NavMeshBuilder.UpdateNavMeshDataAsync(data, GetBuildSettings(), **sources**, sourcesBounds)
Thanks. I will try. I will post possible problems and consequences here.
When the relevant area of the tilemap explodes, the tile and of course the collider there are also destroyed, and only then the "navmesh" path is updated. By doing this, instead of running it in every frame, I run it only when needed. This is how I did it:
(I just used this "Surface2D.BuildNavMesh();") I haven't had a performance test for mobile devices yet. But it seems to work better than the previous method.
using UnityEngine;
using UnityEngine.Tilemaps;
using UnityEngine.AI;
public class DestroyScript : MonoBehaviour
{
public Tilemap tilemap;
public Tile wallTile;
public Tile destructibleTile;
public NavMeshSurface2d Surface2D;
public void Explode(Vector2 worldPos)
{
Vector3Int originCell = tilemap.WorldToCell(worldPos);
ExplodeCell(originCell + new Vector3Int(1, 0, 0));
ExplodeCell(originCell + new Vector3Int(0, 1, 0));
ExplodeCell(originCell + new Vector3Int(-1, 0, 0));
ExplodeCell(originCell + new Vector3Int(0, -1, 0));
ExplodeCell(originCell + new Vector3Int(1, 1, 0));
ExplodeCell(originCell + new Vector3Int(1, -1, 0));
ExplodeCell(originCell + new Vector3Int(-1, 1, 0));
ExplodeCell(originCell + new Vector3Int(-1, -1, 0));
Surface2D.BuildNavMesh();
}
void ExplodeCell(Vector3Int cell)
{
Tile tile = tilemap.GetTile<Tile>(cell);
if (tile == wallTile)
{
return;
}
if (tile == destructibleTile)
{
tilemap.SetTile(cell, null);
}
}
}