Skip to content

Getting Started Tutorial

Shi Johnson-Bey edited this page Feb 19, 2024 · 4 revisions

Getting Started With TDRS

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.

Step 0: Install TDRS

Please install TDRS using the instructions provided on this page.

Step 1: Create an empty scene

  1. In the Project window, right-click and select Create > Scene
  2. Name the scene "TDRS Tutorial"
  3. Double-click the scene to open it in the editor.

Step 2: Add a social engine to your scene

  1. Add a new empty GameObject to the scene by right-clicking the scene hierarchy and selecting Create Empty.
  2. Rename the GameObject to "SocialEngine" to keep us organized.
  3. First click the "SocialEngine" GameObject. Then, click the Add Component button in the Inspector.
  4. Add a new SocialEngineController component to the GameObject.

Step 3: Create an Agent Schema

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.

  1. In the project explorer window, right click and select Create > TDRS > Agent Schema.
  2. Name it "CharacterSchema"
  3. Set the Agent Type field to "character"
  4. Add a new entry to the Stats list.
    1. Set the stat name to Confidence
    2. Set the base value to 0
    3. Set the min value to 0
    4. Set the max value to 100
    5. Set "Is Discrete" to true
  5. Add your agent schema to the Agent Schemas list on the SocialEngineController

Step 4: Create a Relationship Schema

Next, we are going to create a schema for the relationships between our agents. This process is very similar to that for agents.

  1. In the project explorer window, right click and select Create > TDRS > Relationship Schema.
  2. Name it "CharacterToCharacterSchema"
  3. Set the Owner Type and Target Type fields to the "CharacterSchema" we created previously.
  4. Add a new entry to the Stats list.
    1. Set the stat name to Friendship
    2. Set the base value to 0
    3. Set the min value to 50
    4. Set the max value to -50
    5. Set "Is Discrete" to true
  5. Repeat the previous step, adding a new Romance stat.
  6. Add your relationship schema to the Relationship Schemas list on the SocialEngineController

Step 5: Add agents

  1. Create an empty GameObject and name it "Ameera".
  2. Add an AgentController component
  3. Set the UID field to ameera. This is a unique ID used to identify Ameera within the relationship system.
  4. Set the Agent Schema field to the "Character schema we created previously.
  5. Repeat the steps above and create three other characters (jamal, lily, and the player).

Step 6: Add Relationships

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.

  1. Right-click on "Ameera" and select Create Empty to create an empty child object.
  2. Rename the object "Ameera to Jamal". This name helps us remember who owns the relationship and who the feelings are directed toward.
  3. Add a RelationshipController component to the new GameObject.
  4. Set the Owner to "Ameera" and the Target to "Jamal"
  5. Repeat this process for "Ameera" to all the other agents
  6. 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.
    1. 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.

Step 7: Create a new agent traits

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.

  1. Right-click in the Project window and select Create > TDRS > Trait.
  2. Name the trait "Friendly"
  3. Set the following fields in the ScriptableObject:
    1. Set Trait ID to friendly
    2. Set Trait Type to agent
    3. Set Display Name to Friendly
    4. Set description to [owner] is friendly. TDRS will internally replace "[owner]" with the UID of the agent.
  4. Repeat the above and create another trait with the ID attractive and the display name Attractive.
  5. Under the stat modifiers for attractive add an entry that boosts the agent's confidence:
    1. Set Stat Name to Confidence
    2. Set the Value to 5
    3. Set the Modifier Type to: FLAT
  6. Add both traits to the Traits list on the SocialEngineController
  7. Click on Jamal in the scene Hierarchy
  8. Under "Base Configuration" add friendly to Jamal's base traits
  9. Click on Ameera in the scene Hierarchy
  10. Under "Base Configuration" add attractive to Ameera's base traits

Step 8: Create new relationship 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.

  1. Create traits with the following traitID/Display Names and modifiers
    1. friend/Friend
      1. Modifiers: (Friendship, 7, FLAT)
    2. spouse/Spouse
      1. Modifiers: (Romance, 4, FLAT)
    3. lover/Lover
      1. Modifiers: (Romance, 8, FLAT)
    4. angry-at/Angry-At
      1. Modifiers: (Friendship, -5, FLAT)
  2. Add the traits to the SocialEngineController
  3. Add an entry for friend under the base configurations the following relationships:
    1. Ameera to Player
    2. Jamal to Player
    3. Jamal to Lily
  4. Add an entry for spouse under the base configurations the following relationships:
    1. Ameera to Jamal
    2. Jamal to Ameera
  5. Add an entry for lover on the following relationships:
    1. Ameera to Lily
    2. Lily to Ameera
  6. Add an entry for angry-at on the relationship from jamal to the player.

Step 9: Create a new social rule for friendly characters

Next, we will create a new social rule that adds a friendship buff to all characters with the friendly trait.

  1. Right-click inside the Project window and select Create > TDRS > Social Rule.
  2. Name it "FriendlyFriendshipBoost".
  3. 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 the friendly trait before applying its modifiers.
  4. Add a new modifier entry
    1. Set the Stat Name to Friendship
    2. Set the value to 8
    3. Set the Modifier Type to FLAT
  5. Add the social rule to the Social Rules list on the SocialEngineController component.
  6. Click the Play button to see how this social rule has been applied all of Lily's outgoing relationships since they have the friendly trait.

Step 10: Create a new social rule for attractive characters

Last, we will create a new social rule that make characters more romantically attracted to attractive characters.

  1. Right-click inside the Project window and select Create > TDRS > Social Rule.
  2. Name it "AttractiveRomanceBoost".
  3. 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 the attractive trait before applying its modifiers.
  4. Add a new modifier entry
    1. Set the Stat Name to Romance
    2. Set the value to 8
    3. Set the Modifier Type to FLAT
  5. Add the social rule to the Social Rules list on the SocialEngineController component.
  6. Click the Play button to see how this social rule has been applied to everyone who has a relationship toward Lily.

Wrap-Up

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.