Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question AI Planner - Bad performance spikes on world state update

Discussion in 'AI & Navigation Previews' started by Noxalus, Jan 5, 2021.

  1. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    80
    Hello everyone!

    After many days of research, I don't know what is the good way to avoid the huge performance spikes when we update the world state of a single agent.

    The situation is simple, my agent has multiple possible actions like Move, Drink, Eat, Play, etc... Each time an action is finished, I call the method DecisionController.UpdateStateWithWorldQuery() to make sure the changes in the agent's trait data are sent to the planner.

    Doing that will start over a new planification and I know it, but that's what I want. As it's a game, things always update and I can't let the agent plan 1000 steps in the future and be sure he will be able to perform them because the world state could differ from what he think it will be.

    In total, my agent's plan contains 15 actions and 2 terminations. In the DecisionController, every action "Next State Update" is set to "Use World State". And here is the semantic query I use:

    upload_2021-1-5_18-6-49.png

    I have a simple benchmarking scene with a single agent and 15 semantic objects with the Slot trait (and 7 traits in total):
    upload_2021-1-5_18-8-52.png

    I've used a stopwatch (from System namespace) to check the time to perform the DecisionController.UpdateStateWithWorldQuery() call, and it takes an average of 12ms, here is what I get on the profiler:

    upload_2021-1-5_18-13-33.png

    With the "new" API, I can directly get the semantic objects from the SemanticQuery component, and in the same situation it takes something like 0.4ms.

    I know it's possible to limit the number of object the agent can see using "First" or "Last" X objects, or even using a radius filter, but 15 objects is not that much and it's already really expensive.

    Do you know how I can reduce the cost of that call?