Home › Forums › A* Pathfinding Project › Support › Performance Issues
Tagged: AIfollow
This topic has 2 voices, contains 18 replies, and was last updated by Aron Granberg 104 days ago.
| 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. I followed the tutorial and added pathfinding to an object. It worked fine. It becomes very laggy with obvious pauses while it does the pathing. 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 |
| December 26, 2011 at 17:33 #1144 | |
|
Ian |
I believe I have solved the issue I was having. 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. 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. |
| February 2, 2012 at 21:07 #1398 | |
|
ZDI |
Aron, 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. |
| 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. |