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 : SerializedMonoBehaviourInherits: SerializedMonoBehaviour (Odin)
Remarks
ItemSpawner provides two spawning APIs that both ultimately call INetworkScriptableFactory.NetworkSpawn():
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 andPhysics.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.Static spawn — Takes an
ItemIDand resolves the factory viaItemDatabase.GetFactory(). Returns the spawnedItemdirectly 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
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.
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.
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
spawner
FactorableSpawner<Item, ItemData>
Configurable spawner with factory and variant selection (Odin serialized)
Common Pitfalls
Instance spawn requires Inspector configuration
The instance Spawn() method relies on the FactorableSpawner being configured with a valid factory and variant in the Inspector. A null or misconfigured spawner causes a NullReferenceException or InvalidCastException at the factory cast.
Static spawn does not set position
Unlike the instance method, Spawn(ItemID) does not position the item. The caller must set item.transform.position after spawning.
Physics.SyncTransforms() is immediate
The instance spawn calls Physics.SyncTransforms() to push the new position to the physics engine immediately. This is necessary because the item may have a Rigidbody that needs to be at the correct position before the next physics step.
Play mode only (instance)
The [ShowIf("@UnityEngine.Application.isPlaying")] attribute hides the Inspector button outside of play mode. The method itself has no runtime guard — calling it outside play mode via code will attempt network operations and fail.
See Also
ItemNetwork — network trigger registration on spawned items
FactorableSpawner — generic spawner wrapper
INetworkScriptableFactory — network spawn interface
Last updated