Skip to content

Beacon Handle Extensions

shmellyorc edited this page Sep 23, 2026 · 1 revision

BeaconHandleExtensions provides typed convenience helpers for reading Beacon payloads without expanding the small immutable BeaconHandle core API.

The positional helpers access known payload indexes directly. They do not scan or enumerate the payload collection.


Overview

Feature Description
First-item access Read payload item zero without writing an index
Multi-value TryGet Read the first two through five typed payload values in one call
Fallback values Return a fallback when an item is missing or has another type
Type checks Test whether a payload position contains a requested type
Topic checks Compare a handle against a string or enum topic
Payload checks Test whether a handle has any data

Get

Get<T>() reads payload item zero.

Player player = handle.Get<Player>();

This is equivalent to:

Player player = handle.Get<Player>(0);

Indexed access remains available directly on BeaconHandle when another payload position is needed.


TryGet

Read the first payload item:

if (handle.TryGet(out Player player))
{
    UsePlayer(player);
}

Multiple positional payload items can be read together, up to five values:

if (handle.TryGet<Vect2, int, string>(
    out var position,
    out var score,
    out var reason))
{
    ShowResult(position, score, reason);
}

All requested positions must exist and match their requested types for the multi-value overload to return true.

For indexed access, use the core handle method:

if (handle.TryGet<int>(1, out var damage))
{
    ApplyDamage(damage);
}

GetOr

Return a fallback when the payload is missing or has another type.

First item:

int score = handle.GetOr(0);

Indexed item:

int damage = handle.GetOr(1, 0);

Has

Check the first payload item:

bool hasPlayer = handle.Has<Player>();

Check a specific payload position:

bool hasDamage = handle.Has<int>(1);

IsTopic

Compare the handle topic against a string:

if (handle.IsTopic("PlayerDied"))
{
    // Handle PlayerDied.
}

Or against an enum:

if (handle.IsTopic(GameBeacons.PlayerDied))
{
    // Handle PlayerDied.
}

Enum topics use the same enum-string representation as the Beacon Manager.


HasData and IsEmpty

if (handle.HasData())
{
    // One or more payload items are available.
}

if (handle.IsEmpty())
{
    // No payload items were published.
}

These map directly to the handle's payload count.


Example

BeaconManager.Instance.Subscribe(GameBeacons.PlayerDied, handle =>
{
    if (!handle.TryGet<Vect2, int>(out var position, out var score))
        return;

    if (handle.IsTopic(GameBeacons.PlayerDied))
        ShowDeathScreen(position, score);
});

For the publish/subscribe flow itself, see Beacon Event System. For subscription lifetime helpers such as SubscribeOnce, see BeaconManager Extensions.


Summary

Method Description
Get<TData>() Get payload item zero as TData
TryGet<T1>(out T1) Try to read payload item zero
TryGet<T1, ... T5>(...) Try to read the first two through five payload items
GetOr<TData>(fallback) Read item zero or return a fallback
GetOr<TData>(index, fallback) Read an indexed item or return a fallback
Has<TData>() Test item zero for a type
Has<TData>(index) Test an indexed item for a type
IsTopic(string / Enum) Test the handle's topic
HasData() true when one or more payload items exist
IsEmpty() true when the payload is empty

See Also


Back to Home

Clone this wiki locally