Is using StartPath on Update bad for performance?

Hi, just bought the plugin, and have a quick question. I’m trying to write my own custom movement engine for AIs, and I need to update their path beyond the first frame. I figured I’d put it in Update, but that sounds like a bad idea. Does anyone have any experience or wisdom related to this? Should I tell it to calculate every X frames or seconds instead? Or is there some method I haven’t found that’s great for updating an existing path?

Hi

The built-in movement scripts recalculate their paths every X seconds. Usually every 0.5 to every 1.0 seconds is good enough for most games. Though there is also a more sophisticated mode that recalculates the path more often if the destination changes quickly, and less often if the agent is far away or the destination doesnt change much.

Using it every Update is not recommended. Its really not necessary to do it that often.

1 Like

What’s the more sophisticated way? That sounds super useful.

And yeah, I definitely wanted to avoid doing it every Update :sweat_smile:

Hi

You could use this helper class in your movement script if you want. It’s what the built-in movement scripts use: AutoRepathPolicy - A* Pathfinding Project

Gotcha, I see. Yeah looking into this, this is exactly what I need. My only question is, when I’m using this, I’m trying to call ShouldRecalculatePath(), but it wants an IAstarAI component (I believe), but I’m using something similar to the movement example from the tutorial, and I’m not using anything like the AIPath component currently. What arguments would I use in this situation?

Sorry for the newb-ish question, just trying to learn here.

Ah, yeah sorry. I forgot that script relies on the IAstarAI interface. You could implement that interface for your movement script, or you could just copy and paste the relevant parts that you need from the AutoRepathPolicy class.

I’ll give that a try then. I’m not the best programmer in the world, but maybe this will be a great learning opportunity.

Also btw, hope you’re doing okay- I saw your note about covid! Welcome back to the forums, and get well soon!

1 Like