Timescale and pathfinding

Hi,

I am having an issue where it takes a very long time to calculate a path after having adjusted the Time.timeScale in Unity. Lets say I click a button and set the Time.timeScale to 0.5f. Then I place some objects that need to update the pathfinding grid. Then I set the Time.timeScale back to 1.0f. If I then call for a path, it takes the path a long time to calculate again.

Is there some framerate dependent/independent code that I would need to adjust? My goal is to be able to place roads on a terrain that update the grid while the Time.timeScale is less than one (lets say 0.3f). Then after the player is done placing roads, the time scale will be set back to 1 (or normal speed). And after the timescale is set back to 1, I would like agents to be able to pathfind at normal speed as well.

Thanks for any help.

One thing that might affect it is that by default graph updates are limited to only happen every 0.2 seconds (A* Inspector -> Settings -> Max Graph Update Frequency). I am not sure, but that might be affected by time scale. Pathfinding itself should not be affected by timescale at all.

What exactly do you mean when you say that it takes a long time to calculate a path? Is it the reaction time of the agent? are you looking at some log output? profiler?

1 Like

Hey Aron. Thanks for the reply.

You nailed it. It was the fact that I was trying to place my roads faster than 0.2 seconds apparently. By chance I had limited my road building to 0.2 seconds exactly (purely by chance). When I commented out that code, it stopped working.

Now it makes more sense lol. So, I’m curious, what happens if I set Max Graph Update Frequencey to 0 or 0.1? Will the system sometimes miss graph updates because it’s so fast?

Also, I wanted to tell you that your “GraphUpdateScene” componenet is awesome :slight_smile: It’s saving me so much time, and is very quick and easy to use. Thank you for creating that component! I was doing it manually for a year or two and I was scared to use the component, but now that I am I love it.

1 Like

Hi

No, it will never miss an update, but the updates may be delayed up to that number of seconds. If you set it to zero they will be performed immediately (i.e before the next path is started to be calculated).

Excellent. Thank you very much.

1 Like