Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

I Could Use Some Advice setting AI Priority

Discussion in 'Scripting' started by Masoric, Apr 8, 2021.

  1. Masoric


    May 5, 2019
    Good Afternoon,

    I am looking for some advice on how to efficiently set task priority for units in my game.

    My setup is below.

    • There is a set of needs at a global level. Currently it is in a singleton as a 2D array that contains things like the need itself, the quantity of the need, and a location if necessary, etc.. For better or worse if I can figure out how to hide it/encrypt it from the customer I would really like to move all of this to sqlite DB.
    • Needs are added to the array through a verity of mechanisms. There could be a manual add by the player (such as "mine copper" quantity of 50). But they can also be added when there is some failure to fulfill some other action. That would be something along the lines of adding a request to craft and item, such as a sword, into the queue. The system will check to see if the resources required to craft that sword exist. If the required resources do not exist a "need" will be added to the queue for those items and their quantities.
    • Then the units themselves have individual priorities based on what the player defines. I.E. Mining might be set higher than cutting wood which is higher than crafting, etc. There is also the possibility that multiple needs will share a priority.
    • Every so often the unit checks its current personal priorities against the needs and ranks them. If there are competing priorities there is some logic that makes a decision on which is the first highest priority based on a number of factors and sets the current task/state.

    It has been working so far and as of yet it has not generated any performance problems in my testing. None the less I feel like it could be a lot better I just do not have the experience to know what that might be.

    I guess, at the end of the day, I am just looking for thoughts and suggestions from those of you with more experience.