The Solarnaut Spawner plugin offers developers a robust, reliable implementation for spawning gameplay relevant objects at runtime.
At the core is the Subsystem, which manages all of the Spawners. Spawners are defined by their Definition Table, Conditions, Triggers, LocationProviders, and Contexts. There is also built-in handling for Telegraphing spawns.
Please note that comments found in the source code contain more detail and should be considered correct anywhere it may conflict with this documentation.
The Spawner Subsystem (USolSpawnerSubsystem) knows about
all spawners and all spawned actors in the world. The Subsystem has a
queue for spawners waiting to spawn actors, maintains maps of all
relevant information, sends actor death notifications, and broadcasts
gameplay requests for spawning to all relevant spawners (via
BroadcastTriggerPayload).
The simplest payload to broadcast is just a
GameplayTag, and the simplest thing for a spawner to do is
see if it wants to respond to that Tag or not (using its triggers).
However, the system is open-ended, using
USolCustomPayload as a way to pass any arbitrary data
around.
ASolSpawnerBase is the concrete base class for all
spawners, which can be Blueprinted. It has a set of features that should
be useful in many situations, but new native classes can also extend or
override core functionality when necessary.
GetNumToSpawn uses FMath::RandRange to pick
a number with these values to decide how many actors to spawn.
GetCooldownSeconds.
ArmSpawner and
DisarmSpawner toggle this state. Triggers typically ignore
everything while the spawner is disarmed. Spawner cooldowns work by
temporarily disarming it.
Any Actor class or Blueprint can implement
SolSpawnTelegraphInterface, which consists of one function:
SetTelegraphDuration(float InSeconds). The spawner can set
its own class and duration, but Spawn Definitions can provide their own.
The TelegraphOverride field specifies how to choose the
correct telegraph actor and time. The bOneTelegraph field
enforces only a single telegraph's appearance (at the location of the
first spawned actor), but its delay will apply to the entire group of
actors spawned.
USolSpawnTrigger is the abstract base class for all
triggers, which can be Blueprinted. Initialized in their spawner’s
BeginPlay, they have two main ways of activating. The
first is DoesPayloadMatch, called from the Subsystem’s
BroadcastTriggerPayload. This is the most flexible way to
send events to triggers, and each trigger can determine if they care to
respond to it or not. If they want to respond, they activate using
FireTrigger. The other main activation method is calling
FireTrigger directly, but it is recommended to broadcast
through the Subsystem whenever possible.
Triggers are components, so must be added via the spawner’s component list.
MatchesTagExact) and a TagQuery. These must be unset
or match against a payload’s TriggerTag to fire.
DoesPayloadMatch until it reaches its FireNum.
If FireNum is set to 0, the tags will instead need to match a
FireTriggerQuery.
Actor class filter to match only specific types, as well
as the BlueprintNativeEvent RespondToActor
for more advanced custom filtering.
FireTrigger always calls CanFireTrigger first
to ensure the trigger hasn’t hit its MaxTriggerCount and that
its Spawner is Armed. The provided trigger classes also gate
DoesPayloadMatch with CanFireTrigger so that
they only count while “active”.
Triggers may continue tracking while the spawner is disarmed, then fire immediately once it is re-armed (if it wants to).
USolSpawnLocationProvider is the abstract base class for
all location providers, which can be Blueprinted. Each provider
implements GetSpawnTransforms (in C++ or Blueprint).
Points returned by the provider can be adjusted to find a suitable
ground location automatically (with configurable options for raycasting
and/or navmesh projection).
Location providers are components, so must be added to a spawner’s component list.
GetRandomPointInNavigableRadius.
RandPointInBox.
FSolSpawnDefinition specifies what will be spawned: an
AActor derived class, GameplayTags to identify the
definition, a Weight to use when picking multiple definitions, and an
optional Telegraph Actor class. This struct is used to create DataTable
assets. There can be one table per spawner, or a table can be shared
across as many spawners as desired.
USolSpawnCondition is a simple object that can filter a
Spawn Definition’s Actor class or GameplayTags. Spawners have their own
list of conditions. Triggers can also define their own list of
conditions, so that a spawner with multiple triggers might only be able
to spawn a particular actor from one of those triggers. All conditions
must pass for a definition to be eligible.
USolSpawnContext is the abstract base class for contexts.
A spawn context typically modifies a spawned actor in some way, though
it isn’t required to. Contexts can be configured on Spawners and
Triggers, and sent in payloads.
SetLifeSpan with a
random value between a set Min and Max.
SetActorScale3D with
a random value between a set Min and Max.
PlaySoundAtLocation to play the sound at the spawned
actor’s location.
SetMaterial on them.
SolSpawnDefinition.SpawnDefinitionTable to the one created in step
1.
Sol.Spawner.List — displays the names of all registered
spawners in the log.
Sol.Spawner.ShowSpawner <name> — displays the
information (implemented in GetDebugString) of any
spawner whose name matches in the log.
Sol.Spawner.BroadcastTag <tag> — broadcasts the
specified tag through the Subsystem.
Sol.Spawner.DestroyActors <name> — destroys all
actors currently spawned by the specified spawner and reports the
count.
PerformSpawnFromPayload with an empty
payload. No triggers are used, and the spawner's Armed state is
ignored. However, spawning still adheres to the normal rules (like not
spawning beyond MaxConcurrentSpawns).
CanFireTrigger).