Class SteamCallbacks
Steam callbacks and call results: subscribe by generated struct type, await call results as tasks, or receive every message in raw form through a single event. Handlers run on the main thread, or inline on the polling thread when there is no main-thread SynchronizationContext (e.g. headless). On a pipe initialized with External, subscribing and awaiting throw.
Inherited Members
Namespace: Unity.Steamworks.Interop
Assembly: Unity.Steamworks.Interop.dll
Syntax
public static class SteamCallbacks
Properties
ExceptionHandler
Receives exceptions thrown by handlers, which are caught so one subscriber cannot break
the others. Defaults to UnityEngine.Debug.LogException.
Declaration
public static Action<Exception> ExceptionHandler { get; set; }
Property Value
| Type | Description |
|---|---|
| Action<Exception> |
PollIntervalMilliseconds
Milliseconds between polls on the callback thread (default 32, minimum 1).
Declaration
public static int PollIntervalMilliseconds { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
CallResultAsync<T>(Func<SteamAPICall_t>, bool)
Starts an async Steam call and returns a task that completes with its result.
steamCall runs under the dispatcher's lock, so the result cannot arrive before the task is registered.
Declaration
public static Task<T> CallResultAsync<T>(Func<SteamAPICall_t> steamCall, bool gameServer = false) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| Func<SteamAPICall_t> | steamCall | Invokes the Steamworks API and returns its SteamAPICall_t. |
| bool | gameServer | The call was made on the game-server pipe; only that pipe's shutdown cancels the task. |
Returns
| Type | Description |
|---|---|
| Task<T> | The call result payload once Steam reports it. |
Type Parameters
| Name | Description |
|---|---|
| T | The call-result struct produced by the invoked API. |
Exceptions
| Type | Condition |
|---|---|
| SteamCallResultException | The call did not start, or completed with an IO failure. |
CallResultAsync<T>(SteamAPICall_t, bool)
Awaits an already-started async call. Prefer CallResultAsync<T>(Func<SteamAPICall_t>, bool): a result that arrives before this method registers the handle is dropped, and the task never completes.
Declaration
public static Task<T> CallResultAsync<T>(SteamAPICall_t call, bool gameServer = false) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| SteamAPICall_t | call | The handle returned by the Steamworks call to await. |
| bool | gameServer | The call was made on the game-server pipe. |
Returns
| Type | Description |
|---|---|
| Task<T> | The call result payload once Steam reports it. |
Type Parameters
| Name | Description |
|---|---|
| T | The call-result struct the invoked API produces. |
DeliverQueuedCallbacks(bool)
Runs this pipe's waiting handlers now, on the calling thread, instead of later on the main thread.
Declaration
public static void DeliverQueuedCallbacks(bool gameServer = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | gameServer | Deliver the game-server pipe's callbacks instead of the client pipe's. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The pipe was not initialized with ExternalPoll. |
RunFrameCallbacks(bool)
Reads the callbacks waiting on a ExternalPoll pipe and delivers them. On the main thread the handlers run before this returns; from another thread they run later on the main thread.
Declaration
public static void RunFrameCallbacks(bool gameServer = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | gameServer | Read the game-server pipe instead of the client pipe. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The pipe was not initialized with ExternalPoll. |
SubmitCallback(HSteamPipe, in CallbackMsg_t, bool)
Delivers one message the application read from the pipe. SteamAPICallCompleted_t messages must be passed too, or awaited call results never complete.
Call it before FreeLastCallback: the payload is copied here.
Declaration
public static void SubmitCallback(HSteamPipe pipe, in CallbackMsg_t msg, bool gameServer = false)
Parameters
| Type | Name | Description |
|---|---|---|
| HSteamPipe | pipe | The pipe the message came from; call results are fetched from it. |
| CallbackMsg_t | msg | The message, as |
| bool | gameServer | The message came from the game-server pipe. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The pipe was not initialized with ExternalPoll. |
Subscribe<T>(Action<T>, bool)
Subscribes a handler to a Steam callback by its generated struct type, e.g.
Subscribe<PersonaStateChange_t>(...). The handler remains subscribed until Unsubscribe<T>(Action<T>, bool) is called.
Declaration
public static void Subscribe<T>(Action<T> handler, bool gameServer = false) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| Action<T> | handler | Invoked with the decoded callback struct. |
| bool | gameServer | Subscribe on the game-server pipe instead of the client pipe. |
Type Parameters
| Name | Description |
|---|---|
| T | The callback struct to receive. |
Unsubscribe<T>(Action<T>, bool)
Removes a handler added with Subscribe<T>(Action<T>, bool). Later callbacks never reach it, but a delivery already under way uses a snapshot of the handlers, so it may still invoke the removed handler.
Declaration
public static bool Unsubscribe<T>(Action<T> handler, bool gameServer = false) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| Action<T> | handler | The same delegate instance that was passed to Subscribe. |
| bool | gameServer | Unsubscribe from the game-server pipe instead of the client pipe. |
Returns
| Type | Description |
|---|---|
| bool | true when a matching subscription was found and removed. |
Type Parameters
| Name | Description |
|---|---|
| T | The callback struct that was subscribed to. |
Events
OnCallback
Receives every client-pipe callback in raw form, after the callback's typed subscribers. The payload is valid only inside the handler; see SteamCallbackMessage.
Declaration
public static event Action<SteamCallbackMessage> OnCallback
Event Type
| Type | Description |
|---|---|
| Action<SteamCallbackMessage> |
OnGameServerCallback
Receives every game-server-pipe callback in raw form; see OnCallback.
Declaration
public static event Action<SteamCallbackMessage> OnGameServerCallback
Event Type
| Type | Description |
|---|---|
| Action<SteamCallbackMessage> |