background info:
In my game, monsters use RichAI to navigate on the map. When a monster is initialized from scratch, I simply set its position to the expected spawn position, it works. if this monster died, I send it back to a “pool”, then take it out when needed, and set its position again, it will not be shown at the target position.
after a bit of research, I found there is a API called Teleport() that is recommended to set up a monster‘s position. it works in terms of the result. However, there is a log error will occur after it. Although, it doesn’t break the game while I am testing it in editor’s Play Mode, but it leaves me scares for the future when my game is running on player’s PC.
I need help with this issue, what’s the correct way to deal with this situation, in terms of a safe code when use Teleport to set up a position.
What I have done for experiments:
1 based on recommendation written on the API, set the destination with the target position of the agent before calling Teleport.
2 call or not call seeker.CancelCurrentPathRequest(); before calling Teleport or setting destination.
3 SetPath(null) when the agent is disabled or OnEnable
No matter I do or not do no2 and 3, the error always occur. check log as below:
my version is 5.3.3 , unity version is 2022.3+
Path Failed : Computation Time 0.00 ms Searched Nodes 0
Error: Canceled by script (Seeker.CancelCurrentPathRequest)
Canceled by script (Seeker.CancelCurrentPathRequest)
Canceled by script (Seeker.CancelCurrentPathRequest)
Path Number 67 (unique id)
UnityEngine.Debug:LogWarning (object)
AstarPath:LogPathResults (Pathfinding.Path) (at ./Packages/com.arongranberg.astar/Core/AstarPath.cs:829)
AstarPath:<.ctor>b__84_3 (Pathfinding.Path) (at ./Packages/com.arongranberg.astar/Core/AstarPath.cs:645)
Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.Sync.BlockableChannel`1/Receiver<Pathfinding.Path>) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:367)
Pathfinding.PathProcessor/<>c__DisplayClass27_0:b__0 () (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart ()