- Home /
Lag when baking NavMesh at run time
Since there are pushing object function and a randomly moving enemy in my game, it needs to bake NavMesh again when the object was moved. Although I set the baking time only at the period of pushing the object, there is a little lag every time baking, even if I try to reduce the baking frequency. Is there a way can solve this problem?
Here is the baking NavMesh script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 public class NavigationBaker : MonoBehaviour {
 
     public NavMeshSurface surfaces;
 
     PlayerController playerscript;
 
     // Use this for initialization
     IEnumerator Start(){
         playerscript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
         while (true)
         {
             if ((playerscript.canPush) && (playerscript.movedObject != null)){ //when pushing
                 surfaces.BuildNavMesh (); //bake NavMesh
             }
             yield return new WaitForSeconds (3);
         }
     }
 }
Answer by adriant · Jan 08, 2018 at 09:47 AM
Inside the while loop, when the condition in if is false there will be a wait for 3 seconds executed. So this causes the next possible baking to happen after those 3 seconds have passed.
Do you mean there is a lag between the moment surface.BuildNavMesh() is called and the moment when the NavMesh is updated? 
yes, when the Nav$$anonymous$$esh is updated, there is a lag
Your answer
 
 
             Follow this Question
Related Questions
Agents on run time baked navmesh behave weirdly 0 Answers
surface.Bake(); no such command 2 Answers
Navmesh as physics collider? 0 Answers
NavMeshSurface on Generated Mesh Won't Bake 0 Answers
NavMesh Bake at Runtime 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                