Hello! I want a Bot to always follow me. The moment it reaches me right now, it stops moving. Is there a notify that I can use to restart the Move To function?
I assume if I run the Move To Actor on Tick / Behavior Tree it will have a worse performance?
For things that are scarce, like “NPCs that follow the character,” doing something inside Tick(), or maybe doing something on a timer that runs 5 times a second, is not a performance problem to worry about.
Generally, I will do something like “if I’m further away than Y from the player character, issue a move-to command, else if I’m between X and Y, set the speed to lerp(walk, run, (D / (Y-X))), else do nothing.”
This will let the NPC run when it’s further away, and walk when it’s closer, so it stays at a consistent-ish distance/speed without starting/stopping too much.
There is no need to use Tick. Yes it will affect the performance especially if you have lots of pawns sprouting about. You might also run into thread synchronization issues or even NPE if your target gets destroyed (i.e Killed) somewhere in the middle.
If you are using the MoveTo
nodes either from C++ or BP through the AIController. You have 2 options.
- You can bind the
OnMoveCompleted
node to an event. When the movement finishes it will trigger that event where you can add the logic needed once it completes it’s movement cycle. - You can override the
MoveCompleted
function in your custom AI controller subclass to do the same thing.
In your case if you want the bot to follow you, simply just call the MoveTo
node again.
One thing to note is that this is a universal movement complete notification so you might need to add branching logic depending on case, especially if you have other logic that might cause the bot to stop movement.