Skip to content

Create Traits Using YAML Files

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

How to create traits using YAML files

Users can create new traits using YAML files as an alternative to using ScriptableObjects. This method is especially useful for games that wish to enable users to mod the relationship configurations. This guide does not cover how to create a mod system, but a simple one could be created using StreamingAssets and some custom code that uses the TraitYamlLoader class.

For reference, YAML is a data serialization language that is popular for configuration files. It has better readability than JSON at the expense of stricter formatting rules. However, all JSON is valid YAML. So, the example below works with JSON too (with some syntactical adjustments). If you want to better familiarize yourself with YAML, the following page has been helpful: https://quickref.me/yaml.

  1. Right-click in the Project window and select Create > TDRS > Traits YAML.
  2. Name the file whatever you wish
  3. This file expects traits to be supplied in a list with similar data fields as the scriptable object versions. Each of the fields is provided below
  4. Remove the placeholder data and add your traits to the file
  5. Add a new TraitsYamlFileLoader component to the same gameobject os the SocialEngineController.
  6. Add the trait file to the Trait Yaml Files list on your TraitsYamlFileLoader instance.
  7. Now the trait is available to use in base configurations and social events.

Below are explanations of each of the fields:

  • traitID: (Required) A unique identifier for this trait to differentiate it from other traits. By convention, the name should be all lowercase with underscores instead of spaces, and no punctuation.
  • traitType: (Required) Specifies if the trait is to used with agents or relationships.
    • Valid values: "agent" or "relationship"
  • displayName: (Required) A regular text name to be displayed in GUIs. This can contain spaces, capitalization, and punctuation.
  • description: A short text description provided to explain why the agent/relationship has the trait. You can use the [owner] value in your description to have the owner of an agent trait's UID inserted into the description. If the trait is a relationship trait, the [target] template value is also available.
  • modifiers: A list of modifiers to apply to the agent/relationship the trait is attached to.
    • statName: (string)The name of the stat to apply the modifier to
    • value: (number) The value to apply to the stat
    • modifierType: How should the value be applied to the stat.
      • FLAT: Add the Value to the stats base value
      • PERCENT_ADD: Treat the Value as a percentage where (1.0 is 100%) and increase the base stat value by the sum of all calculated modifiers with type PERCENT_ADD. See Stats for an example of how this is calculated.
      • PERCENT_MULTIPLY: Treat the Value as a percentage where (1.0 is 100%) and increase the base stat value by the given percentage. See Stats for an example of how this is calculated.
  • conflictingTraits: A list of Trait IDs of traits this trait cannot coexist with on the same agent/relationship.

Example Definitions

- traitID: jerk
  traitType: agent
  displayName: Jerk
  description: "[owner] is a jerk"
  modifiers:
    - statName: Confidence
      value: 5
  conflictingTraits:
    - friendly

- traitID: friendly
  traitType: agent
  displayName: Friendly
  description: "[owner] is friendly"
  conflictingTraits:
    - jerk

- traitID: friend
  traitType: relationship
  displayName: Friend
  description: "[owner] considers [target] to be a friend"