NEEDSIM Life simulation version 1.0.1
Manual
By FANTASIELEBEN UG (haftungsbeschränkt)
Programming:
Art:
1 Product description
The NEEDSIM Life simulation makes it quick and easy to simulate daily life of humans, wildlife or even machines. Assign interactions to game objects, and NPCs will use them to satisfy their needs: You can make people watch TV when they are bored, or have animals drink from a lake when thirsty.
-
Creative freedom: You decide which needs to simulate with NEEDSIM Life simulation.
-
One world, many species: Goblins have different needs than humans.
-
Design how often agents have to satisfy a need: Make thirst decay fast, but comfort decay slowly in a hot vacation paradise.
-
Interactions can satisfy or decay multiple needs at different rates: Watching TV might satisfy the entertainment need, but give characters an appetite for snacks.
-
Objects have slots that agents can go to when interacting with them: Make a double bed out of a single bed by adding a slot.
-
Freely drag and drop slots around in the scene to decide where characters will have to be when running the interaction.
-
Add a slot to an agent and other agents can run interactions there, for example allowing a fox to eat a bunny.
-
Slot allocation: A smart system takes care of distributing available slots to agents.
-
Multiple databases for different scenes can be managed. In one scene people might dance and drink in a club, in the next one people could have needs related to working in an office.
-
Chose whether agents focus on their goals or whether they focus on the utility provided by the available interactions.
-
Based on innovative research presented at the Foundations of Digital Games Conference and the Vienna Game AI Conference.
-
Innovative AFFORDANCE TREE technology can be used by programmers to manage computational complexity in large worlds with many different interactions - the NEEDSIM Life simulation can scale to your needs.
-
Six example scenes with various scripts and assets, such as beautiful spritesheets and animations for wildlife.
-
Manage needs, species, interactions and databases in the editor extension released with the NEEDSIM Life simulation for Unity.
-
Debug information: Understand agent state and slot state with our debug information, visible in play mode.
Please be aware that we do not offer a navigation or animation solution. However, our examples provide ideas on how to work with the Unity NavMesh and Mecanim.
2 Further material
3 The basics
That agents satisfy needs at objects is the basic principle the NEEDSIM Life simulation builds upon. Agents are all form of non-player characters (NPCs). The NEEDSIM Life simulation is a multi-agent system: It manages multiple problems that arise if many agents inhabit the same world.
Agents are driven by their needs. Needs have a satisfaction value with a minimum value of 0, and a maximum value of 100. Usually each need will become more urgent at a specific rate, agents might for example become more hungry at a rate of 0.1 per second.
Needs can become critical, and can become satisfied. You can select values for these states, for example you can say that hunger is critical below 20, and satisfied above 80. This affects at which point agents that use goal oriented behaviors from our sample agent scripts will think about a new action. Furthermore, as a designer, you might want to decide to let an actor that has been critically hungry for a long time die of starvation - you will have to ask for the respective state in a script then.
Hopefully however, the actor will eat something before that happens. Eating is an interaction. Interactions satisfy (or decay) at least one need at a specific rate, for example eating might satisfy the hunger motif at a rate of 0.3 per second.
Interactions can be used at NEEDSIM Nodes - a drop down menu in the inspector allows to select an interaction for a game object that has a NEEDSIM Node component attached to it. For example a banana might afford the interaction to be eaten to the environment - just select the eating interaction in the inspector.
Each agent belongs to one species. Examples for species could be different kinds of people, animals like cats or even trucks and cars.
What differentiates species of agents is which needs they contain. Cats might not have the need to mark a territory if they encounter a tree, whilst dogs might have such a need. Zombies might not feel a need to socialize, and thus, unlike humans, that have this need, will not use phones.
NEEDSIM Manager component
You need exactly one NEEDSIM Manager per Scene. You can attach the NEEDSIM Manager Component to an empty game object, or use our prefab. In the NEEDSIM Manager you have to reference the database you want to use in the scene.
Each object that is affected by the NEEDSIM Life simulation needs a NEEDSIM Node component in Unity. You can select whether the NEEDSIM Node affords an interaction to other agents, and if so, add slots to which agents can go to use the interaction. To add agents to the simulation tick the isAgent box in the NEEDSIM component, and add a way for agents to move, for example a Unity NavMeshAgent.
The name comes from the AFFORDANCE TREE, a tree data structure managing the simulation: Each NEEDSIM Node refers to a node in the AFFORDANCE TREE.
4 Sample Scenes
4.1 Naturleben
4.2 Hasenjagd
4.3 Fuchsalarm
4.4 Simple Room
4.5 Spawn Beds
4.6 Simple Time
5 Setting up your data
We made the NEEDSIM Life simulation so that you can quickly bring your unique vision to life and test ideas efficiently. You can set up species, needs and interactions by selecting Window -> NEEDSIM Life Simulation. Figure
9↓ explains how to add, remove and edit needs, figure
10↓ explains the editor view for species, figure
11↓ shows the editor view that allows management of interactions. Multiple databases can be managed in the advanced view explained in figure
12↓. Once you created a new database you can select it in your scene using the NEEDSIM Manager explained in figure
8↓.
5.1 NEEDSIM Manager
5.2 Needs View
5.3 Species View
5.4 Interaction View
5.5 Advanced View
6 Setting up the NEEDSIM Node Component
Once you have defined some needs, species and interactions you want to work with you can set up the characters and props in the scene to work with the simulation. To do so, attach the NEEDSIMNode.cs script to the respective game objects. Two typical settings are discussed in this manual, the case of a smart object that offers interactions in figure
13↓, and the case of a smart object that is an agent in figure
14↓.
6.1 NEEDSIM Node providing interactions
6.2 NEEDSIM Node that is an agent
Part III. Running NEEDSIM Life Simulation in your Project
7 How to use NEEDSIM Life simulation along common solutions
7.1 Integrating your Navigation Solution
In the example scenes that come with the product we use the UNITY NavMesh. However, with a few steps you should be able to use the NEEDSIM Life Simulation with any navigation solution. For the system to work agents need to be able to arrive at slots. You might have to make the following changes in order to use your navigation solution:
-
Define arrival at a slot: Open the Blackboard.cs file in NEEDSIM > Scripts > Agent. The method HasArrivedAtSlot() has a condition we use for the UNITY NavMesh. You might need a different condition depending on your project and your navigation solution.
-
Replace the call of SetDestination(): Open the Blackboard.cs file in NEEDSIM > Scripts > Agent. The method AcceptSlot(...) contains a call of SetDestination() on the UNITY NavMesh agent.If you don’t want to use the UNITY NavMesh you have to call a similar method from your own solution.
7.2 Using Mecanim for Animation
The states the artificial intelligence is in are usually not the same as the states of an animation system. We don’t provide a solution for animation at the moment, and can not yet promise that we will provide a solution in the future.
However, some scenes like our Naturleben scene have sample scripts demonstrating a simple idea on how to interface our simulation with Mecanim. The idea is that you name the conditions for your transitions the same way as the interactions. Then you can call TryConsumingAnimationOrder(Animator animator) on your NEEDSIM Node.
This method assumes that in the animator a trigger named "Movement" exists, and that for each interaction a trigger with the same name exists in the animator, e.g. that for the interaction "Eat" a trigger named "Eat" is in the animation and is used to transition into a state or sub-state-machine that plays animation(s) for eating. See an example animator in figure
15↑.
This method, and our sample scripts in the Naturleben scene, provide a starting point when you want to integrate the NEEDSIM Life Simulation into your project.
7.3 Integrating NEEDSIM Life simulation with Behavior Trees, GOAP, etc
NEEDSIM Life simulation can easily be integrated into the behaviors or actions of behavior trees, goal oriented action planning (GOAP), queues, or other agent-centric control solutions.. The example behavior scripts are written in a way that the code used in the Run methods of our example actions can quickly be copy/pasted into your control solution. NEEDSIM Life simulation ships with an example scene (see fig.
4↑) that shows how the NEEDSIM Life simulation is turned on/off. NEEDSIM Life simulation is satisfied with being run in the IDLE Behavior of your agent-centric solution, so that if your NPC ends up in a fight he can go use GOAP/BT/etc. and think about the world from her/his perspective: Where is my enemy, where is cover, etc. But once she/he is out of a fight there is no more need to do so, and the agent can be controlled by the environment/NEEDSIM Life simulation again.
Part IV. Tips, Tricks & Troubleshooting
8 Tips & Tricks
8.1 Debugging
A NEEDSIM Manager with the default database loaded is automatically added to the scene if you press play. However, using the NEEDSIM Manager Prefab, or adding the script to a game object in the scene, gives you configuration options as well as the option to load different scenes. You can turn off the debug log to reduce string operations (but you can of course also just delete the method body in the script to further optimize).
8.1.2 Slot debugging
Slots can be in different states. In order to see the state of a slot whilst the game is running, you need to activate gizmos in Unity.
-
If a slot is green it is available to agents.
-
If a slot is yellow, it is reserved to an actor.
8.2 Frequently Asked Questions
How can I use multiple interactions on one object?
Whilst this is not properly tested coders should be able to use the Simulation.Affordance.AddInteraction() method to add multiple interactions to the Simulation.Affordance of an Affordance Tree node., and can then select which one to start either randomly, or by using a name. In the NEEDSIMNodeInspector there should be some commented code that might work and would allow you to add multiple interactions from the inspector view.
Why is AddNEEDSIMNode not automatically called inside the NEEDSIMNode?
A reason is that AddNEEDSIMNode(NEEDSIMNode node, NEEDSIMNode parent) is used to create advanced representations of the world, and a NEEDSIMNode might not know which parent it should be attached to. For example the NEEDSIMRoot.BuildAffordanceTreeFromNode(NEEDSIMNode node) method uses the scene hierarchy to build the Affordance Tree. This allows you to build a representation of a world with villages with houses with objects such as beds and tables, and the nodes have to know their parents.
9 Troubleshooting
The NEEDSIM Node Inspector is weird
Did you rename a NEEDSIM Node? In that case you need to change the typeof(...) to the new name in the NEEDSIMNodeInspector.cs:
CustomEditor(typeof(NEEDSIMNode))]
public class NEEDSIMNodeInspector : Editor
My agents don’t do anything
If your agents are not doing anything, please make sure that in the species assigned to the actor you checked at least one need. Please make sure you have an interaction that can satisfy this need. Please make sure there is a NEEDSIM Node in the scene that has this interaction. Make sure that across the objects that have interactions satisfying the need there are enough slots for all agents.
My agents are not leaving the object they are using.
Please make sure the interaction afforded by the object satisfies the agents current need - The value at which it increases need satisfaction should be higher than the value at which the need decays.
Please make sure your navigation solution works properly
The example agent that comes with the product relies on navigation information. When using the example agent or similar solutions, please make sure slots are on your NavMesh solution, and that arrival at a slot can be properly validated.
There can be issues with multiple agents going to overlapping slots, for example if they have a rigidbody attached - there should be enough distance between slots, so that agents can use them.
Please make sure each game object uses only one NEEDSIM Node
Having more than one NEEDSIM Node component on the same game object can result in values being overwritten.
10 Patches
Patch 1.0.1
-
The inspector of the NEEDSIMNode now shows a toggle “Use non-random start values”. If ticked you can select specific start values for each need.
-
NEEDSIMNodes now have a method that will help the method NEEDSIMRoot.BuildAffordanceTreeFromNode(NEEDSIMNode node) build an Affordance Tree from a specific node.
-
The scene 04. Simple Room now lets you edit at runtime how needs change per second, and how interactions affect needs. The scripts InputFieldRuntimeEditing.cs and SpawnUIRuntimeEditing.cs are new, as well as the prefab InputFieldRuntimeEditing.cs
-
The example action provided in DoSingleInteraction.cs had a misleading name, and we renamed this script to SatisfyUrgentNeed.cs
Polish of API and documentation
-
We added more comments.
-
The sample scripts now have tooltips instead of comments for their properties.
The API was unnecessarily complicated so we made some changes that are unlikely to affect anyone so soon after the initial release.If they do, please write to support@fantasieleben.com and we will help you out. The benefit is that potential sources or errors are reduced, and that code completion and documentation are less cluttered. The changes include:
-
The method Simulation.AffordanceTreeNode.Update() was only called once from the root (recursive method to update all nodes in the tree), so to improve the API we made Simulation.Manager.Instance.UpdateAffordanceTree() the place to update the tree.
-
Simulation.NeedItem constructor no longer has min/max values as the default values were used.
-
Unnecessary strings in our Simulation.Strings class were removed, as the features they were written for no longer exist or have changed.
-
Some properties that are potential sources of error if used wrongly have been made internal instead of public in Simulation.GameDataManager, Simulation.Goal, Simulation.SimulationData and Simulation.AffordanceTreeNode. Simulation.SimulationData now exposes ChangePerSecond - see scene 04. Simple Room for how to work with it.
-
The Uncritical state has been removed from the Simulation.Needs.NeedSatisfactions enum, as it is meaningless in the current simulation.
-
Methods of the NEEDSIMEditor that where exposed by mistake are no longer exposed.
-
The default name for new databases has been changed.
-
Small mistakes in the manual have been corrected.
-
A potential source of errors in how the Affordance Tree was build has been fixed.