Skip to content

Game Events ​

Game events describe notable occurrences in a game, such as collecting an item or crossing a score threshold. They are separate from effects: an event reports what happened, while the game pack decides how that event is used.

For a Unity game using the Crowd Control plugin, report occurrences with CrowdControlBehavior.TriggerEvent. Event definitions and argument IDs must already match the game pack's published event manifest. Unreal projects can define events in the plugin with Setup Game Event; see the Unreal game-event guide.

Define events in a C# game pack ​

EffectPack<TConnector> exposes a GameEvents collection. Use each dictionary key as the stable event ID and GameEvent.Name as its streamer-facing name. Add argument definitions with stable IDs, then generate or publish the pack menu so the IDs are available to event sources.

csharp
using System.Collections.Generic;
using CrowdControl.Games.Events;

GameEvents["coin_collected"] = new GameEvent("Coin Collected")
{
    Args =
    {
        ["total_coins"] = new NumericEventArg("Total Coins")
        {
            Min = 0,
            Integer = true,
        },
        ["coin_type"] = new LiteralEventArg("Coin Type")
        {
            Literals =
            {
                ["gold"] = new EventLiteral("Gold"),
                ["silver"] = new EventLiteral("Silver"),
            },
        },
    },
};

NumericEventArg supports optional inclusive Min and Max values and an Integer flag. LiteralEventArg exposes a Literals collection; each literal has its own stable ID and display name. Occurrences should use matching argument IDs and, for literal arguments, the literal's ID rather than its display name.

The public definition types are in CrowdControl.Games.Events: GameEvents, GameEvent, EventArguments, EventArg, NumericEventArg, LiteralEventArg, EventLiterals, and EventLiteral. The EffectPack.GameEventTriggered event reports EventOccurrence objects when a definition fires.

Trigger events from pack-observed game state ​

For packs that can read the game state, GameEvent.WhenCondition and GameEvent.WhenChanged<T> create definitions evaluated by the pack runtime:

csharp
using System.Collections.Generic;
using CrowdControl.Games.Events;

GameEvent lowHealth = GameEvent.WhenCondition(
    "Low Health",
    () => PlayerHealth < 25,
    () => new Dictionary<string, object?>
    {
        ["health"] = PlayerHealth,
    });
lowHealth.Args["health"] = new NumericEventArg("Health")
{
    Min = 0,
    Integer = true,
};
GameEvents["low_health"] = lowHealth;

Define any emitted argument IDs in the event's Args collection as well. WhenCondition fires on a transition from false to true (not simply because it is already true at the first evaluation). WhenChanged<T> captures an initial value, then fires when the value changes according to its comparer. The runtime resets these trigger baselines when the connector disconnects.

For occurrences detected directly by the game, such as Unity gameplay callbacks, report them from the engine when the transition actually occurs rather than polling every frame. The plugin's async overload indicates whether the occurrence was queued for transmission, not whether the pack has processed it.

Reference ​