Installation
Installing the package is simply unpacking the .unitypackage downloaded via Asset Store through Package Manager.
Import the package and you are ready to go!
Setting up an AI
Create an empty game object and attach an Agent Component. An UtilityPlanner component will automatically be added.
Agent Component is responsible for managing its current state, such as idle, moving, planning or executing an action.
- Utility Planner, reference to utility planner, if you want to change the way it plans, you can drop in a different one.
- State, shows the current state the agent is in. This is here for debug purposes and not to be changed in the editor.
- Events, has a collection of Unity Events for almost every notable changes in the Agent planning and executing processes.
- Agent Debugger and below is runtime information or debug buttons you can use to help understand your agent.
Utility Planner Component takes your available actions and find the best action given the current circumstances.
- Paused, setting this to true will pause the planning and executing workflow of the agent.
- Update Type, determines if it will be called in Update, LateUpdate, FixedUpdate or Script. Script allows you to manually handle it yourself for Turn Base Games.
- Idle Duration, is the time the agent stays in idle before starting a new plan.
- Start Plan on Awake, enabled will plan immediately.
- Start Plan Delay, delays the plan at the start, good if you want to slightly have a different timing to your agents.
- Find Actions On Awake, automatically searches for actions nested under the Agent.
- Include In Active Actions, will search even actions that are turned off.
- Execute Event Zero Score Actions, will allow an action to perform even if it returns 0 score. This is useful if you want your Agent to choose even the worse move. Alternatively in your consideration, return 0.1 instead or go to the action and set the MinScore to be 0.1
- Show Logs, enabled will allow Debug.Log messages to show. Useful for debugging issues.
- Log Types, let us filter out what type of logs to show.
Once these 2 components are added, the Agent will be able to think on its own. However, it would need 3 more scripts to actually do something!
- Utility Action, is a monobehaviour that contains a list of consideration and will actually do the action such as “Eat or Sleep”
- Consideration, is a scriptable object that ****returns a score to a question. i.e How Hungry am I?
- Data Context, is a monobehaviour implementing IAgentDataContext that is used to pass information down to actions & consideration. Think of this as a way of retriesving the agent states / world states. This is automatically searched by the agent.
We will be making an Agent that has to choose between saving a person or not. In these cases, you’d consider a few things, can I save them? do I want to save them? And naturally the context is, what is my relationship to them?
For simplicity sake, I will choose to make the Agent save the person if they are his friend. So let’s be the the Agent’s friend 😅.