Skip to content

Create SocialEvents Using ScriptableObjects

Shi Johnson-Bey edited this page Feb 21, 2024 · 2 revisions

How to create Social Events using ScriptableObjects

Users can create Social Event types directly in the Unity Editor using ScriptableObjects. Using ScriptableObjects has the benefit of taking advantage of Unity's asset management pipeline.

  1. Right-click in the Project window and select Create > TDRS > Social Event.
  2. Name the new asset whatever you wish.
  3. Set the desired social event fields (described below).
  4. Add the asset to the Social Events list on the SocialEngineController within your scene.
  5. Try dispatching the event with some characters.
    • The sample code in the repo implements a MockSocialEventCreator (located in Assets/TDRS_Demo/Scripts/). This class allows you to specify an event type and a list of characters to bind to the event roles (in order).

Social Event Scriptable Object Fields

  • Event Name: (required) The name of the event (used when specifying which event to dispatch)
  • Roles: (optional) The names of roles of characters who are involved in the social event
  • Description: (optional) A string description describing the social event.
    • This string uses a [role_name] template syntax that will substitute role names with the UIDs of the agents bound to those roles. For example, a description of [group_a] ended their feud with [group_b], will expand to montagues ended their feud with capulets assuming that agents with UIDs montagues and capulets were bound to roles group_a and group_b, respectively.
  • Responses: This is where you specify how agents should react to this event. Each entry corresponds to a different response. Agents can respond to the same event multiple times, assuming they pass the preconditions for multiple response entries.
    • Preconditions: These are RePraxis query statements that run against TDRS's database. Any variables bound with the query can be used within the effect functions.
    • Effects: Effect functions to trigger when dispatching this event. You can read more about effect functions on the Social Events Page.
    • Description: A response-specific description. Both even role names and precondition variable names are eligible for substitution using the square bracket syntax.

Sample Scriptable Object

Below is a screenshot of a Social Event Scriptable Object that defines a betrayal event.

screenshot of social event scriptable object