Very slow after adding HasPath() to Move action

Hi.

Loving the course so far. Managed to get this far without any major issues. So far all steps of the course have been spot on.

I have been following this section as best I can. However, after adding in the HasPath() implementation to the MoveAction. The movement has severely slowed down and halts when moving grid positions. I suspect something is calculating too often when it does not need to. As it now seems very unusable.

Not sure if this is the nature of a simple path finding algo. Or something is wrong in my code? Just concerned I will struggle on the next steps to complete

I have added my project here, as I know someone may ask for code examples.

https://drive.google.com/file/d/1iDgUp2hiOxnAfUtEeByqLjxhFbj0hvGC/view?usp=sharing

Regards
Paul

You mean the game freezes for a second whenever the unit changes grid position? That would indeed be the pathfinding calculating tons of positions when the unit moves.
How big is your map? How big is the max move distance?

The bigger the map the longer it takes to calculate a path. And the bigger the move distance the more nodes it needs to check if there’s a path to them.

Sounds like you didn’t do anything wrong, it is simply the case that the pathfinding built in the course is functional but is not optimized so it does slow down significantly as you increase the complexity with a bigger map or more pathfinding calculations per frame.
The solution is work on optimizing the pathfinding or use a well built asset like the A* Pathfinding Project or change the code to only calculate the paths when the unit reaches the final position and not every time it changes position.

1 Like

Hi

Thanks for the quick response.

It was setup as per the tutorials. 10x10 grid. Max move distance 4.

I have looked into this a bit more late last night and this morning. checked through all the pathing finding. Not found anything too obvious…

The only thing I have done is removed a lot of debug.logs throughout the solution that were in Update() methods.

This seems to have resolved it now. Either that or that plus a restart of Unity.

I have now increased the grid size and max move distance to test and seems to work a lot better now. Its usable again!

I will look at only finding a new path when the target node is reached. As it makes sense to only look at possible new routes when a new route is required. (Good optimization tip).

Thanks for your help. Looking forward to the next steps (Grenade Action).

Regards
Paul

1 Like

Privacy & Terms