Reporting Game Events
Game events report notable gameplay occurrences—such as collecting an item, defeating a boss, or reaching a score—to Crowd Control. A game pack can use those occurrences to decide when to offer or trigger effects.
The Unity plugin reports event occurrences; it does not define the event menu. Define and publish the event in the game's Crowd Control pack first. Use the same event ID in Unity, and use the published argument IDs as the keys in the values you report.
Report an event
Add or reference the CrowdControlBehavior component that manages the active session. Report the event at the gameplay transition, after the session is ready. The one-argument TriggerEvent overload is fire-and-forget and can also be connected to a Unity event in the Inspector:
using CrowdControl.Client.Unity;
using UnityEngine;
public class BossController : MonoBehaviour
{
[SerializeField] private CrowdControlBehavior crowdControl;
private void OnBossDefeated()
{
crowdControl.TriggerEvent("boss_defeated");
}
}The event ID must match the ID in the game pack exactly. Do not report an event every frame; call it when the occurrence actually happens.
Include event arguments
Use the overload with an argument dictionary when the event includes values. Keys must match the argument IDs in the pack definition, and values should be JSON-serializable:
using System.Collections.Generic;
using CrowdControl.Client.Unity;
using UnityEngine;
public class CoinManager : MonoBehaviour
{
[SerializeField] private CrowdControlBehavior crowdControl;
private void OnCoinCollected(int totalCoins)
{
crowdControl.TriggerEvent(
"coin_collected",
new Dictionary<string, object?>
{
["total_coins"] = totalCoins
});
}
}For example, the pack definition for coin_collected must declare an argument with the ID total_coins. Keep event and argument IDs stable when updating a game pack so existing game code continues to match them.
Check whether an event was queued
Use TriggerEventAsync when gameplay logic needs the result. Its Task<bool> result reports whether the event was queued for transmission; it is not an acknowledgement that the game pack has acted on the event.
private async void OnBossDefeated()
{
bool queued = await crowdControl.TriggerEventAsync("boss_defeated");
if (!queued)
{
Debug.LogWarning("The boss-defeated event could not be queued.");
}
}Call TriggerEventAsync only after the Crowd Control session is ready. Use the SessionReady callback or the component's SessionReadyEvent in the Inspector to coordinate session-dependent behavior. The callback can be used for session setup; occurrences should still be reported when their gameplay transitions happen.
For the underlying EventOccurrence type and C# pack-side game event definitions, see the API documentation.
