Events Examples
This section demonstrates practical examples of using Google Play Games Services Events in Unreal Engine projects. All examples assume that the player is already signed in to Google Play Games Services and that all events have been created and configured in the Google Play Console in advance.
Events are lightweight counters managed by Google Play Games Services and are typically used to track cumulative actions such as kills, matches played, items collected, or other long-term statistics.
Basic Usage Flow
A typical events flow in a game looks like this:
- The player signs in to Google Play Games Services.
- Events are incremented during gameplay as actions occur.
- Event values can be loaded when needed to display progress or sync state.
- Loaded event data is used for UI, progression logic, or analytics-style feedback.
Incrementing an Event During Gameplay
The most common use of events is incrementing them when a gameplay action occurs.
Example scenario: increment an event every time the player defeats an enemy.
- Call Increment Event with the corresponding
EventID. - Pass the amount to increment, usually
1.
This is a fire-and-forget operation. The function does not return a result and does not require callbacks.
The EventID must exactly match the identifier of the event created in the Google Play Console.
This approach is ideal for frequent actions, as it is lightweight and handled asynchronously by Google Play Games Services.
Loading All Events
In some cases, you may want to retrieve the current values of all events associated with the player.
Example scenario: display event-based progress in a statistics or profile screen.
It is recommended to call Load Events with bForceReload set to true. This ensures that the returned values always reflect the most recent state stored on the Google Play Games Services backend. In practice, the performance difference compared to cached loading is minimal.
Typical usage pattern:
- Call Load Events after the player has signed in or when opening a stats screen.
- Enable
bForceReloadto fetch fresh data from the server. - Store the returned array of
FGooglePlayEventfor later use. - Use the event values to update UI elements or gameplay logic.
Loading a Single Event
If only one specific event value is required, loading a single event is more efficient than loading all events.
Example scenario: check progress for a single long-term objective.
Typical usage pattern:
- Call Load Event with the target
EventID. - Enable
bForceReloadto ensure the value is up to date. - Use the returned
FGooglePlayEventto read the current counter value.
This approach reduces overhead when only one event is relevant to the current context.
Important Notes and Common Mistakes
- All Events API functions require the player to be signed in to Google Play Games Services.
- Event IDs must exactly match the IDs defined in the Google Play Console.
- Events are cumulative counters and cannot be decremented or reset via the API.
- Incrementing an event is safe to call multiple times and is designed for frequent usage.
- Event data may be cached locally unless a forced reload is requested.
- Events are best suited for long-term counters, not high-frequency real-time statistics.
These examples cover the most common event usage patterns and are sufficient for the majority of games that need simple, reliable progression or statistic tracking.