Hello,
I’m having a rather weird bug with Unity’s navmesh system (I’m using Unity Free 4.2). Basically, the navmesh system itself works correctly, the unit goes from A to B and avoids the obstacles. However, sometimes if I try to log the remainingDistance variable as it moves it stays at zero the whole time. This is slightly annoying because I want to know whether the unit is moving so that I can draw its selectionbox at the right position (this is for a RTS game), and of course I’m using the “remainingDistance” variable to know when the unit has reached its destination.
What really confuses me is that for two identical units (same prefab, same script, same everything as far as I can tell), one will have the correct variable and the other one won’t. Even weirder, the units who are “bugged” still behave normally if I don’t let them stop. What I mean is, I tell unit 1 to go from A to B. It will bug out and say that remainingDistance is 0 despite it clearly moving (let me reiterate that even when I say a unit is “bugged”, it still moves around as expected so it’s not like the navmesh system itself doesn’t work). If I wait until it reaches B and then tell it to go to C, the same will happen -except the position will be recalculated once, at the time of the click-. But if I give it another order mid-moving, then suddenly it starts working normally. So if I keep giving it new orders it somehow works, but if it ever stops once, then it’s going to bug again until I give two orders in a row.
Now there are obviously hacky ways to solve it, such as treating any click as a double-click or issuing the command twice if the unit was not moving before. But it’s a dirty hack and I’d rather solve the problem than hide it with a hack. If it’s possible to solve it, that is.
Thanks in advance
Was wondering if you have solved this problem? I am also interested in the solution as I have the same problem with my project with the "remainingDistance" variable.
– RiehlWow you must have looked for quite some time to find that forsaken post. Unfortunately, nope I never truly solved this problem. Then again I haven't worked on that project of mine for over a year. A bit concerning to see that the issue is still present with the newer versions, though I suspect it's the kind of bug that's also very hard to track down. Basically I think your best bet is to implement a small hack, either one of those I mentioned in the original post or find a new (perhaps cleaner) one. Please report on this thread if you ever find a definitive solution though!
– Pyxidiumfrom my understanding remainingdistance is 0 because it is hitting every path if you get the object stuck then it should become higher than 0.
– Jiles