ItemSpawner

MonoBehaviour that spawns items over the network. Provides two spawn paths: an instance method using a serialized FactorableSpawner (configured in the Inspector), and a static method that spawns any item by ItemID via ItemDatabase.

Definition

Namespace: Paragon.Townskeep.ItemSystem Assembly: Townskeep.dll

public class ItemSpawner : SerializedMonoBehaviour

Inherits: SerializedMonoBehaviour (Odin)

Remarks

ItemSpawner provides two spawning APIs that both ultimately call INetworkScriptableFactory.NetworkSpawn():

  1. Instance spawn — Uses the FactorableSpawner<Item, ItemData> field, which is configured in the Inspector with a specific factory and variant. The spawned item is positioned at the spawner's transform and Physics.SyncTransforms() is called to immediately apply the position to the physics engine. An Odin [Button] attribute makes this callable from the Inspector during play mode.

  2. Static spawn — Takes an ItemID and resolves the factory via ItemDatabase.GetFactory(). Returns the spawned Item directly without positioning it — the caller is responsible for placement.

Both methods accept optional ownerID (for client ownership) and predicted (for client-side prediction) parameters.

Quick Lookup

Goal
How

Spawn from Inspector

Click the Spawn button in play mode

Spawn from code (configured variant)

itemSpawner.Spawn(ownerID, predicted)

Spawn any item by ID

ItemSpawner.Spawn(itemID, ownerID, predicted)

Methods

Spawn (instance)

Spawns an item using the serialized FactorableSpawner, positions it at the spawner's transform, and syncs physics transforms.

Parameter
Type
Default
Description

ownerID

ulong?

null

Network owner client ID. null = server-owned.

predicted

bool

false

Whether to use client-side prediction.

Spawn pipeline:

Spawn (static)

Spawns any item by ItemID using the ItemDatabase to resolve the factory. Returns the spawned item without positioning it.

Parameter
Type
Default
Description

itemID

ItemID

The item + variant identifier

ownerID

ulong?

null

Network owner client ID. null = server-owned.

predicted

bool

false

Whether to use client-side prediction.

Returns: The spawned Item instance.

Serialized Fields

Field
Type
Description

spawner

FactorableSpawner<Item, ItemData>

Configurable spawner with factory and variant selection (Odin serialized)

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated