Skip to content

CrowdControlBehavior

Inherits MonoBehaviour

Public Member Functions

void

Dispose()

Releases all resources used by this component and disconnects from Crowd Control.

void

Connect()

Initializes and connects the Crowd Control client.

void

LaunchInteractLink()

Launches the interact link URL in the user's default web browser.

string?

GetInteractLink()

Gets the interact link URL from the Crowd Control client.

void

Disconnect()

Disconnects from the Crowd Control service and disposes the client instance.

void

ClearToken()

Clears the stored JWT token, forcing a full re-authentication on the next connection attempt.

void

Ping()

Sends a ping to the Crowd Control service and logs the result.

Task

StopAllEffects()

This method attempts to stop all running effects via the Crowd Control effect scheduler. This will return false if any of the effect stop functions throw an exception.

bool

TryGetMetadataObject(string key, out IMetadata value)

Attempts to get a metadata object from the Crowd Control client. This method will return false if the metadata loader is not initialized, if the specified key does not exist in the metadata, or if the value cannot be cast to TValue.

bool

TryGetMetadataValue(string key, out TValue value)

Attempts to retrieve a metadata value from the Crowd Control client. This method will return false if the metadata loader is not initialized, if the specified key does not exist in the metadata, or if the value cannot be cast to TValue.

bool

TryGetMetadataString(string key, out string value)

Attempts to retrieve a metadata value from the Crowd Control client. This method will return false if the metadata loader is not initialized, if the specified key does not exist in the metadata, or if the value cannot be cast to TValue.

void

UpdateCustomEffects()

Updates custom effects in the Crowd Control system by loading effects from the configured effect loader using merge mode. This operation runs asynchronously and requires both a valid Crowd Control connection and an assigned EffectLoader. If either prerequisite is not met, an error is logged and no update is performed. Only custom effects are included in the update.

bool

CloneEffect(string sourceEffectID, string[] destEffectIDs)

Documentation inherited from WebSocket.CrowdControl.CloneEffect.

Task

ShowEffects(string[] codes)

Documentation inherited from WebSocket.CrowdControl.ShowEffects(string[]).

Task

ShowEffects(IEnumerable codes, string? message, = null)

Documentation inherited from WebSocket.CrowdControl.ShowEffects(IEnumerable<string>, string?).

Task

ShowAllEffects(string? message, = null)

Documentation inherited from WebSocket.CrowdControl.ShowAllEffects(string?).

Task

HideEffects(string[] codes)

Documentation inherited from WebSocket.CrowdControl.HideEffects(string[]).

Task

HideEffects(IEnumerable codes, string? message, = null)

Documentation inherited from WebSocket.CrowdControl.HideEffects(IEnumerable<string>, string?).

Task

HideAllEffects(string? message, = null)

Documentation inherited from WebSocket.CrowdControl.HideAllEffects(string?).

Task

EnableEffects(string[] codes)

Documentation inherited from WebSocket.CrowdControl.EnableEffects(string[]).

Task

EnableEffects(IEnumerable codes, string? message, = null)

Documentation inherited from WebSocket.CrowdControl.EnableEffects(IEnumerable<string>, string?).

Task

EnableAllEffects(string? message, = null)

Documentation inherited from WebSocket.CrowdControl.EnableAllEffects(string?).

Task

DisableEffects(string[] codes)

Documentation inherited from WebSocket.CrowdControl.DisableEffects(string[]).

Task

DisableEffects(IEnumerable codes, string? message, = null)

Documentation inherited from WebSocket.CrowdControl.DisableEffects(IEnumerable<string>, string?).

Task

DisableAllEffects(string? message, = null)

Documentation inherited from WebSocket.CrowdControl.DisableAllEffects(string?).

Public Static Functions

void

ClearStoredToken()

Clears the stored JWT token, forcing a full re-authentication on the next connection attempt.

Private Functions

void

Start()

Unity callback invoked when the component is enabled. Initializes and connects the Crowd Control client if autoConnect is enabled.

void

Stop()

Stops and disposes the Crowd Control client instance, if any.

void

FixedUpdate()

Unity physics update loop; forwards timing to the Crowd Control client for processing.

void

OnDestroy()

Unity callback invoked when the component is destroyed; ensures disposal.

Protected Functions

void

~CrowdControlBehavior()

Finalizer to ensure resources are released if Dispose() wasn't called.

void

Dispose(bool disposing)

Core dispose pattern implementation.

Public Attributes

string

GameID

The game identifier used when connecting to the Crowd Control service.

string

DisplayName

The display name used when connecting to the Crowd Control service.

string

ApplicationID

The application identifier used for authentication with the Crowd Control service.

UnityGameStateManager?

GameStateManager

Component that provides the current WebSocket.GameState to Crowd Control.

UnityEffectLoader?

EffectLoader

Component responsible for finding and registering UnityEffectBase instances.

UnityMetadataLoader?

MetadataLoader

Component responsible for finding and registering UnityMetadataBase instances.

bool

AutoConnect

Whether to automatically connect to Crowd Control on start.

bool

AutoReconnect

Whether to automatically reconnect to Crowd Control when the connection is lost while a session is active.

bool

AutoAddCustomEffects

Whether to automatically add custom effects defined in the EffectLoader to the service on startup.

bool

WaitForPingResponse

Whether to block on ping responses. This is for testing purposes only and should generally be false in production.

bool

PersistLoginToken

Whether to persist the JWT token for reconnecting between executions.

bool

PreserveBetweenScenes

Whether to preserve the manager when switching between scenes.

UnityEvent?

SessionReadyEvent

UnityEvent invoked when the Crowd Control session is ready. This can be used to trigger in-game responses to the session being ready. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeReceived event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

SessionEndedEvent

UnityEvent invoked when the Crowd Control session has ended. This can be used to trigger in-game responses to the session ending. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the SessionEnded event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

AuthCodeReceivedEvent

UnityEvent invoked whenever an authentication code is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeReceived event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

AuthCodeRedeemedReceivedEvent

UnityEvent invoked whenever an authentication code redemption result is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeRedeemedReceived event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

AuthCodeErrorReceivedEvent

UnityEvent invoked whenever an authentication code error is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeErrorReceived event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

LoginTokenReceivedEvent

UnityEvent invoked whenever a JWT login token is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the LoginTokenReceived event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

EffectReceivedEvent

UnityEvent invoked whenever an effect request is received from the Crowd Control service. This can be used to trigger in-game responses to effect requests. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the EffectReceived event, but not both, to avoid duplicate handling of effect requests. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

UnityEvent?

EffectUpdateEvent

UnityEvent invoked whenever an effect class update is sent to the Crowd Control service. This can be used to trigger in-game responses to effect class updates. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the EffectUpdate event, but not both, to avoid duplicate handling of effect updates. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Private Attributes

string?

m_jwt

Backing field for the JWT token used for authentication with the Crowd Control service. This is set when a new token is received and is used for reconnecting if the connection is lost.

Properties

bool

HasValidToken

[get, ]

Gets a value indicating whether there is a valid JWT token available for authentication with the Crowd Control service.

bool

Connected

[get, ]

Gets a value indicating whether the Crowd Control client is currently connected. True if the client is created and connected; false otherwise.

Scheduler

Scheduler

[get, ]

Gets the Scheduler instance used by the Crowd Control client for scheduling effect execution. Throws an exception if the client is not initialized.

WebSocket.CrowdControl?

CrowdControl

[get, ]

bool

IsDisposed

[get, ]

Gets a value indicating whether this component has been disposed.

static

bool

IsStoredTokenValid

[get, ]

Gets a value indicating whether there is a valid JWT token stored for authentication with the Crowd Control service.

bool

IsTokenValid

[get, ]

Gets a value indicating whether the currently stored JWT token is valid for authentication with the Crowd Control service.

Events

Action

SessionReady

Event invoked when the Crowd Control session is ready. This can be used to trigger in-game responses to the session being ready. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the SessionReadyEvent event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

SessionEnded

Event invoked when the Crowd Control session has ended. This can be used to trigger in-game responses to the session ending. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the SessionEndedEvent event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(ApplicationAuthCode)

AuthCodeReceived

Event invoked whenever an authentication code is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeReceivedEvent event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(ApplicationAuthCodeRedeemed)

AuthCodeRedeemedReceived

Event invoked whenever an authentication code redemption result is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeRedeemedReceivedEvent event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(ApplicationAuthCodeError)

AuthCodeErrorReceived

Event invoked whenever an authentication code error is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the AuthCodeErrorReceivedEvent event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(string)

LoginTokenReceived

Event invoked whenever a JWT login token is received from the Crowd Control service. This can be used to trigger in-game responses to authentication events. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the LoginTokenReceivedEvent event, but not both, to avoid duplicate handling of authentication events. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(EffectRequest)

EffectReceived

Event invoked whenever an effect request is received from the Crowd Control service. This can be used to trigger in-game responses to effect requests. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the EffectReceivedEvent event, but not both, to avoid duplicate handling of effect requests. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(EffectState)

EffectUpdate

Event invoked whenever an effect class update is sent to the Crowd Control service. This can be used to trigger in-game responses to effect class updates. Note that this event is invoked on the Unity main thread, so it's safe to perform Unity operations in response to it. Subscribers should use either this event or the EffectUpdateEvent event, but not both, to avoid duplicate handling of effect updates. This event is invoked between Update() and LateUpdate() in the Unity lifecycle, so it will be processed after all Update() calls but before any LateUpdate() calls.

Action

(IEnumerable>)

MetadataChanged