Triggers
Triggers enable the automation of server side actions at a set moment in time or as the result of another server event from Unity Gaming Services (UGS).
They enable Cloud Code scripts and modules to be run automatically, without the need for a client to make a request to the server.
Events
An event defines a change in state that has occurred in the server. Events can be emitted by internal Unity Gaming Services, such as the Authentication service, or by the Scheduler service.
For example, every time a player signs in, the Authentication service emits an event.
Refer to Events and Supported UGS events for more information.
Scheduler
Use the Scheduler service to emit events at a set or recurring moment in time.
For example, a scheduler enables you to do the following:
- Send an announcement to all users wishing them a happy new year at 00:00:00 UTC on January 1st.
- Change a game theme at 00:00:00 UTC on the first day of every month.
- Reward top players at the end of every month.
Triggers
The Triggers service monitors a stream of internal events, emitted by Unity Gaming Services and the Scheduler service. Triggers allow users to define rules to automatically perform a chosen action (for example, run a Cloud Code script) when UGS emits a particular event.
A trigger can enable use cases such as:
Use case | Event emitted by | Triggered by | Action |
---|---|---|---|
Initialize player data in Cloud Save every time a new player signs up | Authentication | Signed up event | Run a Cloud Code module or script. |
Sends a push message to all users wishing them a happy new year | Scheduler | Scheduled event | Run a Cloud Code module. |
Reward top players with in-game currency at the end of season | Leaderboards | Reset event | Run a Cloud Code module or script. |
Send a push message to the player whose score was beaten | Leaderboards | Score submitted event | Run a Cloud Code module. |
Announce a level up to all players in joined lobbies | Cloud Save | Key saved event | Run a Cloud Code module. |
Moderate player actions | Moderation | Moderation event | Run a Cloud Code moderation script. |
Filters
Filters are optional conditions that you can add to a trigger to define when the trigger fires. For example, you can define a filter to only fire a trigger for a Leaderboard event when a player submits a score of 100 or more.
Refer to Filters for more information.
Note: Currently, you cannot create triggers with filters using the CLI. Use the Triggers API or the Unity Cloud Dashboard.
Next steps
Take a look at the following guides to learn more about Triggers:
Guide | Description |
---|---|
Events | Learn about how events work, how they are emitted and their structure. |
Trigger structure | Learn about the structure of a trigger and how you can associate it with an event. |
Supported UGS events | Learn about the different types of events that can be emitted by UGS. |
Schedule events using the CLI or API. | Learn how to create scheduled events. |
Define triggers using the CLI, API or Unity Cloud Dashboard. | Learn how to define triggers to run Cloud Code scripts or modules when an event is emitted. |
Access control | Learn about the access control model for Triggers. |