Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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


    Jan 9, 2018
    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:


    I have a simple benchmarking scene with a single agent and 15 semantic objects with the Slot trait (and 7 traits in total):

    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:


    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?