- Home /
Objects not updating at runtime if not selected in hierarchy?
Hello,
I have two cubes that are used a NavMesh and NavAgent to move between four different way points. Anytime the cube enters one trigger, it will randomly select another way point from a list and move to that way point.
When running the game, if I have either cube selected, they both move around the way points just as I would expect. But, if I select something else in the hierarchy window (such as one of the way points), the cubes will stop moving entirely. I can leave it for a few minutes, they don't move, but then I select one of the cubes and they start moving again.
Here is the method I am using to select a new way point;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Waypoint")
{
currentWaypoint = waypoints [Random.Range (0, waypoints.Count)];
}
}
The code works just as I would expect, so I am assuming this issue is something about the script not executing when the object is not selected. I have no way to debug this issue and I would greatly appreciate any insight! Thanks!
So if you enter play mode with nothing selected, nothing happens?
Hello,
If I select one of the waypoints (as opposed to an NPC) and then click start, the NPCs will bounce between 1-2 waypoints and then stop on whatever waypoint they are on. I can then select an NPC and they will start bouncing between the waypoints as I would expect.
I have also tried building the solution (where it is not possible to select anything) and the NPCs just bounce between a few waypoints and then stop.
The script does seem to work fine.. it is very simple, and if I have an NPC selected I can watch the "current waypoint" get updated in real time (it just picks a random waypoint from a list and moves to that waypoint).