I got a small script for removing my monster the problem is when i execute it the game go down to 1 frame per minute. After some tests i found the problem it is line 4. where i Stop the NavMeshAgent when i remove it there is no game freeze but i need the agent to stop.
NavMeshAgent .speed = 0 also lead to a freeze i realy dont know what goes wrong…
After some more testing it seems like if i do a NavMeshAgent.stop lag is there for 100% when i remove it i have a chance that there is no lag and after some time the game go back to normal fps
Edit : Ok got it now it have to do with the Agent Size Radius every monster with a Agent Size that is to small cause that freeze…
looks like every thing smaller then 0.01 can cause a freeze at 0.001 it is a 100% freeze
Edit2: This also removed the lag that some time came up when instantiating a Monster…
Destroy(gameObject) will also cause the freeze when the size is 0.001
At the moment i am to lazy to port my old A* from java or to write a new one in c# thtas the main reason using navmesh and those small values gave me the best results when the monster moved through a maze…
I also played with diferent nav mesh sizes and other values but dont got any progress
Where i get the Path from
Code
public class PathFinding
{
private NavMeshPath [] path;
public GameObject[] way_points;
public GameObject spawn;
private bool blocking = false;
public PathFinding ( GameObject[] way_points, GameObject spawn)
{
this.way_points = way_points;
this.spawn = spawn;
this.path = new NavMeshPath[way_points.Length];
}
public void DrawDebugLine()
{
for(int i = 0; i < path.Length - 1; i ++)
for (int c = 0; c < path[i].corners.Length-1; c++)
Debug.DrawLine(new Vector3(path[i].corners[c].x,1,path[i].corners[c].z), new Vector3(path[i].corners[c+1].x,1,path[i].corners[c+1].z), new Color(0.0f,0.0f,0.0f),10,false);
}
public bool CalculatePath()
{
path = new NavMeshPath[way_points.Length];
blocking = false;
for (int i = 0; i < way_points.Length-1; i ++)
{
path[i] = new NavMeshPath();
NavMesh.CalculatePath (way_points [i].transform.position, way_points [i+1].transform.position, NavMesh.AllAreas, path[i]);
if (path[i].status != NavMeshPathStatus.PathComplete)
{
blocking = true;
}
}
return blocking;
}
public NavMeshPath GetPath(int index)
{
return path [index];
}
}
where i give it to the navmesh
Code
void Start()
{
this.GetComponent<NavMeshAgent>().SetPath(Main.path_finding.GetPath (way_point));
// when tower are to close Distance is 0
Debug.Log (this.GetComponent<NavMeshAgent>().remainingDistance);
for (int c = 0; c < this.GetComponent<NavMeshAgent>().path.corners.Length-1; c++)
Debug.DrawLine(new Vector3(this.GetComponent<NavMeshAgent>().path.corners[c].x,2,this.GetComponent<NavMeshAgent>().path.corners[c].z), new Vector3(this.GetComponent<NavMeshAgent>().path.corners[c+1].x,2,this.GetComponent<NavMeshAgent>().path.corners[c+1].z), new Color(0.5f,0.5f,1.0f),5,false);
alive = true;
}
Ok agen a stupid mistake i got 3 overlaping navigation meshes (forgot to remove the static modifyer when dublicating some assets)
after removing 2 of them no more problems.