GameDevEducation / UnityTutorial_SimsStyleAI

MIT License
12 stars 4 forks source link

Agents stop working after 20 minutes #1

Open laurentopia opened 1 year ago

laurentopia commented 1 year ago

image tracing image image perform not called seems that in certain conditions the agent unlocks smart object but doesn't release current interaction, the odd aspect of this is that it takes a while before breaking and since OnInteractionFinished is passed as callback and that never breaks in my experience it is weird™

laurentopia commented 1 year ago

and in the case of the other agent image so nothing gets done, it seems, but that's not it, i think this value gets set to performer when it's reached destination so this could be (yet another) unity navmesh related bug.

laurentopia commented 1 year ago

And when adding more agents the problems takes less time to show itself.

IainMcManus commented 1 year ago

Cheers for the detailed rundown, I'll try and look into it this weekend.

IainMcManus commented 1 year ago

@laurentopia sorry for how long this took. I've submitted what I think should fix the issue. With this change I've had 5 AIs run for over an hour without stalling. I think there's an issue with the Unity Navmesh agent where after a time of trying to avoid another AI it stalls out and clears the path info. I'll keep the issue open for now as I'd like to dig more into what's happening on the avoidance side and see if I can implement a fix for the underlying issue.

laurentopia commented 1 year ago

Fantastic, thanks for spending time investigating, I'll look at the change. Even with other pathers you run into stall, sometimes. It might be a good failsafe to add a timeout that calls FindNewBestTask() when stall is detected?

laurentopia commented 1 year ago

I recommend this instead of .y=0, decoupling the AI from game geometry constraints.

image

IainMcManus commented 1 year ago

I switched it over to a similar approach that checks the height delta and the horizontal.

else if (LinkedAgent.hasPath == false) { Vector3 vecToDestination = Destination - transform.position; float heightDelta = Mathf.Abs(vecToDestination.y); vecToDestination.y = 0f;

atDestination = heightDelta < LinkedAgent.height && vecToDestination.magnitude <= DestinationReachedThreshold;

}

laurentopia commented 1 year ago

That'll only work if the plane of action is perpendicular to y.

IainMcManus commented 1 year ago

Yep, that's intentional. I do want to eventually support handling any surface orientation for the AIs but I want to do that in a single commit for clarity.

laurentopia commented 1 year ago

That makes sense, I'll keep an eye out for when you do that.