Trigger structure
Understand the structure of a trigger configuration that defines what to invoke when an event fires.
Read time 2 minutesLast updated 18 hours ago
A trigger configuration defines what should be invoked when an event is fired. It may look like this:
{ "name" : "example-trigger", "eventType" : "com.unity.services.{{SERVICE_NAME}}.{{EVENT_NAME}}.v{{EVENT_VERSION}}", "actionUrn" : "urn:ugs:cloud-code:{{SCRIPT}}", "actionType" : "cloud-code", "filter": "data['parameter'] == 'value'"}
- : The name of the trigger. It must be unique per project.
name - : Used to match the trigger to an event. It is composed of the
eventTypeandeventNamefields, corresponding to theeventVersionandeventNamefields in the event configuration.payloadVersion - : Defines what should be invoked when the trigger is fired. For example,
actionUrninvokes theurn:ugs:cloud-code:TestScriptCloud Code script, orTestScriptinvokes theurn:ugs:cloud-code:TestModule/TestFunctionfunction in theTestFunctionCloud Code module.TestModule - : The type of the action to be executed when the trigger is fired. Currently, only
actionTypeis supported.cloud-code - : An optional field that defines a condition that must be met for a trigger to fire. If the condition isn't met, the trigger doesn't fire. For more information, refer to Filters.
filter
Overlap with events
Triggers are associated with events. When an event is fired, the associated trigger is invoked. The event and the trigger must share the sameeventNamepayloadVersionScheduled events
Given the following schedule configuration:And the following trigger configuration:{ "name" : "recurring-schedule", "eventName": "example-event", "type": "recurring", "schedule": "0 0 * * *", "payloadVersion": 1, "payload": "{\"someBoolean\": true, \"someString\": \"something\"}"}
You can associate the trigger with the event type by setting the{ "name" : "example-trigger", "eventType" : "com.unity.services.scheduler.example-event.v1", "actionUrn" : "urn:ugs:cloud-code:my-script", "actionType" : "cloud-code"}
eventTypeeventNamepayloadVersionUGS events
Given you want to associate a trigger with an event type from UGS, you need to specify the event type in the trigger configuration. For example, if you want to fire a trigger on the Authentication: Signed Up event, you can create the following trigger configuration:Every time a user signs up, the trigger is fired, invoking the{ "name" : "example-trigger", "eventType" : "com.unity.services.player-auth.signed-up.v1", "actionUrn" : "urn:ugs:cloud-code:my-script", "actionType" : "cloud-code"}
my-scriptMultiple events per trigger
You can associate the same event with multiple triggers.
For example, you can create two triggers that invoke when a user signs up.
The first trigger invokes the
add-cloud-save-dataThe second trigger invokes the{ "name" : "auth-cloud-save", "eventType" : "com.unity.services.player-auth.signed-up.v1", "actionUrn" : "urn:ugs:cloud-code:add-cloud-save-data", "actionType" : "cloud-code"}
add-economy-itemsEconomyEvery time a user signs up, both triggers are fire and invoke the associated Cloud Code resources.{ "name" : "auth-economy", "eventType" : "com.unity.services.player-auth.signed-up.v1", "actionUrn" : "urn:ugs:cloud-code:Economy/add-economy-items", "actionType" : "cloud-code"}