Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I Could Use Some Advice setting AI Priority

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

  1. Masoric

    Masoric

    Joined:
    May 5, 2019
    Posts:
    14
    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.

    Regards,
    Masoric