Performance Issues

HomeForumsA* Pathfinding ProjectSupportPerformance Issues

Tagged: 

This topic has 2 voices, contains 18 replies, and was last updated by  Aron Granberg 104 days ago.

Viewing 15 posts - 1 through 15 (of 19 total)
Author Posts
Author Posts
December 26, 2011 at 13:05 #1143

Ian

Hi all.

I have been testing A* for my first game attempt in Unity.
It looks like what I need and will be happy to purchase the Pro version.

I followed the tutorial and added pathfinding to an object. It worked fine.
The problems occur when I attach it to a prefab and then instantiate more than 3 of the prefab.

It becomes very laggy with obvious pauses while it does the pathing.
Im using a grid graph of 19 x 12 nodes. Which I assume is fairly small compared to the one in the example.

It is probably more to do with the way i am using the Pathing rather than your library causing issues.

The Astar Path script is attached to an empty game object and the prefab has a seeker and a character controller.

The grid currently has no unwalkable nodes so it is just calcing a straight path.

If there is any more details you need please let me know.

Unity 3.4.2f3
A* Pathfinding Project v3.0.6

December 26, 2011 at 17:33 #1144

Ian

I believe I have solved the issue I was having.
It was the charactercontroller attached to the object. Once removed the lag is gone.
Although my replacement of a coroutine to move the object is not satisfactory at the moment.

I will continue to work on it.

December 27, 2011 at 11:25 #1149

Aron Granberg

Hm, sounds weird, I know that calling SimpleMove on a character controller multiple times per frame can cause serious lag (says so in the docs anyway, haven’t tried it myself), maybe your script was doing that. Because 4 units or something on a graph that small should cause any lag at all.

December 27, 2011 at 14:06 #1151

Ian

Thanks for the reply Aron.

I was calling SimpleMove in the fixedupdate function. Once i removed it and did the movements using a coroutine using lerp the lag dissapeared.

Im having trouble getting the graph to update when i instantiate new objects then should make the node unwalkable. If you know of any good examples of this please let me know.

Currently trying to use UpdateGraphs and then Sending a “Scan” message. Then forcing it to recalc the path. Does not seem to be updating the graph as yet though.

December 28, 2011 at 12:42 #1155

Aron Granberg

Check out the DynamicObstacle.cs script included.
And also you can look at this page (if you haven’t already done so):
http://arongranberg.com/astar/docs/graph-updates.php

Then Scan function recalculates the whole graph, that would be very slow, best is to use only UpdateGraphs, also make sure your obstacles are in a layer considered as unwalkable by the Grid Graph settings.

January 7, 2012 at 19:15 #1248

Finijtzu

I’m also getting this problem. It seems when I get around 4 units on screen it screws up the pathfinding and reduces the framerate. I’m using your example 1 scene as a template. Then I have scripts that logically populate the target component of the AIfollow script with waypoints. The more units I spawn the more inconsistent it gets. Sometimes units will start to hover above the map and start spinning. It’s very frustrating. I haven’t touched the pathfinding code at all. In your example 1 scene is it calling the Simple move alot. It would seem that it would need too since in that scene you have the target snapped to the mouse. I’m curious, what did you replace the character controller script with?

I did pick up the pro version recently so I’m going to try and load another example scene to see if there are different results.

January 9, 2012 at 02:20 #1258

Finijtzu

NM I got it, now I got hundreds of agents and no framerate issues. It was all my fault. :)

February 2, 2012 at 07:25 #1394

ZDI

Finijtzu, would you mind sharing how you improved your performance? I’m seeing similar low performance with a large amount of agents on the screen.

February 2, 2012 at 19:38 #1395

Kent

I second that request. I’m getting pretty bad performance when walking without adding lots of agents.

February 2, 2012 at 19:42 #1396

ZDI

After some research I have found that my performance hit is coming from all of my agents calling seeker.StartPath() at once. I haven’t worked with coroutines in Unity yet, but I’m going to try implementing that to see if this helps fix the problem. Any suggestions or solutions would be much appreciated.

February 2, 2012 at 19:45 #1397

Aron Granberg

You can try lowering the Max Frame Time setting in the A* Inspector’s settings tab. It’s in milliseconds so 1 millisecond shouldn’t cause any lag for just calculating the paths.
However, if you are using a lot of post-processing, that can be the cause.

February 2, 2012 at 21:07 #1398

ZDI

Aron,
I was incorrect. seeker.StartPath() wasn’t the culprit as I thought. I have 50 agents on screen right now. In each of their start() functions I have seeker.StartPath(). I get minor lag on startup while they each search for their path (my avg Main Thread is 12-14ms, it jumps to 20-25ms until all paths are found) . Currently there are no modifiers on my seeker.

The true culprit is controller.SimpleMove(); When I use the FixedUpdate() code straight from the getting started guide my Main Thread jumps to 30-70ms as all objects are trying to move. I’ve tried some different things to try improving this (using coroutines, lerping, etc) but at this point I’m pretty much at a loss on how to optimize this.

February 2, 2012 at 22:17 #1399

Aron Granberg

Oh, have I used the SimpleMove function in FixedUpdate!?! It shouldn’t be used there. It causes major lag if used more than once per frame. So move that code to the Update function and hopefully you should then see better framerates.
Shame on me, I’m supposed to be somewhat good at Unity programming, and than I make a mistake like that in the Get Started Guide. I will fix that ASAP.

February 3, 2012 at 15:52 #1405

Aron Granberg

Fixed, now the Get Started Guide no longer use the FixedUpdate

February 4, 2012 at 01:19 #1409

Travis

Yes it was a problem with the SimpleMove. See this thread on how I fixed it:

http://forum.unity3d.com/threads/48147-SimpleMove%28%29-killing-performance/page2

Before with the SimpleMove my fps would start chugging at 120 units, now by just using:

transform.position += forwardDir * Time.deltaTime;

I can have 300 (depending on what other scripts are active) and still be over 30fps.

Although getting rid of the SimpleMove has a TON of set backs, not using the CharacterController for transforms, so your collisions are gone unless you add a Ridgid Body, and the Local Avoidance requires it too.

I’ll DL you’re new Getting Started guide and see if it improves performance. I’d like to keep simpleMove and CharacterControllers in the loop, but I’m just not sure how efficient they are.

Viewing 15 posts - 1 through 15 (of 19 total)
Reply To: Performance Issues
Your information:






<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>