-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started Tutorial
This page provides a follow-along tutorial to help you get started with using TDRS in your Unity Projects. For this tutorial, we will create a simulation comprised of three NPC agents and a player. We will cover adding TDRS to your project, defining agents, defining relationships, creating traits, and defining social rules. By the end of this tutorial will have an understanding of how to layout a relationship system in your game.
Please install TDRS using the instructions provided on this page.
- In the Project window, right-click and select
Create > Scene
- Name the scene "TDRS Tutorial"
- Double-click the scene to open it in the editor.
- Add a new empty GameObject to the scene by right-clicking the scene hierarchy and selecting
Create Empty
. - Rename the GameObject to "SocialEngine" to keep us organized.
- First click the "SocialEngine" GameObject. Then, click the
Add Component
button in the Inspector. - Add a new
SocialEngineController
component to the GameObject.
For this step, we will define a schema that says what stats and traits an agent has when it is created. It also says what kind of agent it is since agents can represent characters, factions, etc.
- In the project explorer window, right click and select
Create > TDRS > Agent Schema
. - Name it "CharacterSchema"
- Set the
Agent Type
field to "character" - Add a new entry to the
Stats
list.- Set the stat name to
Confidence
- Set the base value to
0
- Set the min value to
0
- Set the max value to
100
- Set "Is Discrete" to
true
- Set the stat name to
- Add your agent schema to the
Agent Schemas
list on theSocialEngineController
Next, we are going to create a schema for the relationships between our agents. This process is very similar to that for agents.
- In the project explorer window, right click and select
Create > TDRS > Relationship Schema
. - Name it "CharacterToCharacterSchema"
- Set the
Owner Type
andTarget Type
fields to the "CharacterSchema" we created previously. - Add a new entry to the
Stats
list.- Set the stat name to
Friendship
- Set the base value to
0
- Set the min value to
50
- Set the max value to
-50
- Set "Is Discrete" to
true
- Set the stat name to
- Repeat the previous step, adding a new
Romance
stat. - Add your relationship schema to the
Relationship Schemas
list on theSocialEngineController
- Create an empty GameObject and name it "Ameera".
- Add an
AgentController
component - Set the UID field to
ameera
. This is a unique ID used to identify Ameera within the relationship system. - Set the
Agent Schema
field to the "Character schema we created previously. - Repeat the steps above and create three other characters (
jamal
,lily
, and theplayer
).
The placement of relationship GameObjects in the scene hierarchy is up to you. In this tutorial, we place them as child objects of the characters that own the relationship.
- Right-click on "Ameera" and select
Create Empty
to create an empty child object. - Rename the object "Ameera to Jamal". This name helps us remember who owns the relationship and who the feelings are directed toward.
- Add a
RelationshipController
component to the new GameObject. - Set the
Owner
to "Ameera" and theTarget
to "Jamal" - Repeat this process for "Ameera" to all the other agents
- Repeat this process for all other "agents" so that each agent has relationships from themselves toward the others. You do not need to add relationships from the player to the other agents because, in most cases, we dont want to assume the player's feelings about NPCs.
- Overall you should have: Ameera to Jamal, Ameera to Lily, Ameera to Player, Jamal to Ameera, Jamal to Lily, Jamal to Player, Lily to Ameera, Lily to Jamal, and Lily to Player.
During this step, we will make a few traits to attach to our characters. For the tutorial we will use ScriptableObjects. However, you could also define traits using YAML files.
- Right-click in the Project window and select
Create > TDRS > Trait
. - Name the trait "Friendly"
- Set the following fields in the ScriptableObject:
- Set Trait ID to
friendly
- Set Trait Type to
agent
- Set Display Name to
Friendly
- Set description to
[owner] is friendly
. TDRS will internally replace "[owner]" with the UID of the agent.
- Set Trait ID to
- Repeat the above and create another trait with the ID
attractive
and the display nameAttractive
. - Under the stat modifiers for attractive add an entry that boosts the agent's confidence:
- Set Stat Name to
Confidence
- Set the Value to
5
- Set the Modifier Type to:
FLAT
- Set Stat Name to
- Add both traits to the
Traits
list on theSocialEngineController
- Click on Jamal in the scene Hierarchy
- Under "Base Configuration" add
friendly
to Jamal's base traits - Click on Ameera in the scene Hierarchy
- Under "Base Configuration" add
attractive
to Ameera's base traits
The process for creating relationship traits is identical to creating agent traits. Relationship traits have their Trait Type
field set to Relationship
. So, their modifier can only be applied to relationship instances.
- Create traits with the following traitID/Display Names and modifiers
-
friend/Friend
- Modifiers: (Friendship, 7, FLAT)
-
spouse/Spouse
- Modifiers: (Romance, 4, FLAT)
-
lover/Lover
- Modifiers: (Romance, 8, FLAT)
-
angry-at/Angry-At
- Modifiers: (Friendship, -5, FLAT)
-
friend/Friend
- Add the traits to the
SocialEngineController
- Add an entry for
friend
under the base configurations the following relationships:- Ameera to Player
- Jamal to Player
- Jamal to Lily
- Add an entry for
spouse
under the base configurations the following relationships:- Ameera to Jamal
- Jamal to Ameera
- Add an entry for
lover
on the following relationships:- Ameera to Lily
- Lily to Ameera
- Add an entry for
angry-at
on the relationship from jamal to the player.
Next, we will create a new social rule that adds a friendship buff to all characters with the friendly
trait.
- Right-click inside the Project window and select
Create > TDRS > Social Rule
. - Name it "FriendlyFriendshipBoost".
- Add the following text to the preconditions list:
?owner.traits.friendly
. This is a query statement that checks that the owner of a relationship has thefriendly
trait before applying its modifiers. - Add a new modifier entry
- Set the
Stat Name
toFriendship
- Set the value to 8
- Set the
Modifier Type
toFLAT
- Set the
- Add the social rule to the
Social Rules
list on theSocialEngineController
component. - Click the
Play
button to see how this social rule has been applied all of Lily's outgoing relationships since they have thefriendly
trait.
Last, we will create a new social rule that make characters more romantically attracted to attractive
characters.
- Right-click inside the Project window and select
Create > TDRS > Social Rule
. - Name it "AttractiveRomanceBoost".
- Add the following text to the preconditions list:
?target.traits.attractive
. This is a query statement that checks that the target of a relationship has theattractive
trait before applying its modifiers. - Add a new modifier entry
- Set the
Stat Name
toRomance
- Set the value to 8
- Set the
Modifier Type
toFLAT
- Set the
- Add the social rule to the
Social Rules
list on theSocialEngineController
component. - Click the
Play
button to see how this social rule has been applied to everyone who has a relationship toward Lily.
At this point you have a small social network built. Feel free to create new trait types experiment with how they affect the various agent/relationship stats.