Class PrefabRef
Reference to a prefab in the game. These are full GameObjects with components (e.g. NetworkObject, interaction scripts, etc.). For static mesh-only assets (decoration), use MeshRef instead. Use S1MAPI.S1.Prefabs for known Schedule 1 prefab assets.
public sealed class PrefabRef
- Inheritance
-
PrefabRef
- Inherited Members
Constructors
PrefabRef(string)
Create a prefab reference.
public PrefabRef(string name)
Parameters
namestringExact prefab name in FishNet registry
Properties
Name
The prefab name as registered in FishNet
public string Name { get; }
Property Value
Methods
Find()
Find the prefab GameObject from FishNet's spawnable prefabs.
public GameObject? Find()
Returns
- GameObject
The prefab GameObject or null if not found
Instantiate()
Instantiate this prefab locally without network spawning.
public GameObject? Instantiate()
Returns
- GameObject
The instantiated GameObject or null if prefab not found
Remarks
WARNING: Only use this method for prefabs that do NOT have a NetworkObject component.
For prefabs with NetworkObject components (networked prefabs), you MUST use InstantiateNetworked() instead. Using this method on networked prefabs will cause FishNet to crash and break multiplayer functionality.
Use this method only for:
- Static decorative objects without network synchronization
- Client-side visual effects
- Local UI elements
InstantiateNetworked()
Instantiate and spawn a networked prefab on the network (server only).
public GameObject? InstantiateNetworked()
Returns
- GameObject
The instantiated and network-spawned GameObject, or null if prefab not found
Remarks
CRITICAL: You MUST use this method for any prefab that has a NetworkObject component.
Using Instantiate() on networked prefabs will cause FishNet to crash and completely break multiplayer functionality. This is not recoverable without restarting the game.
What this method does:
- Instantiates the prefab as inactive to prevent Awake() from running with uninitialized network state
- Initializes any GUID fields to prevent parse errors (fixes issues with prefabs like ATM)
- Spawns the object on the FishNet network, assigning it a network ID
- Activates the object, allowing Awake() to run with valid network state
Requirements:
- The prefab must be registered in FishNet's spawnable prefabs list
- The prefab must have a NetworkObject component
Examples of prefabs that require this method:
- S1.Prefabs.ATM
- S1.Prefabs.Door (any networked doors)
- S1.Prefabs.Storage (any networked storage containers)
Exceptions
- InvalidOperationException
Thrown if called on client when not server
InstantiateNetworked(Transform, Vector3, Quaternion)
Instantiate and spawn a networked prefab, positioned before network spawn. Sets the transform BEFORE calling FishNet Spawn() so that clients receive the correct world position via replication (critical for prefabs without NetworkTransform).
public GameObject? InstantiateNetworked(Transform parent, Vector3 localPosition, Quaternion localRotation)
Parameters
parentTransformParent transform (set before spawn)
localPositionVector3Local position relative to parent
localRotationQuaternionLocal rotation relative to parent
Returns
- GameObject
The instantiated and network-spawned GameObject, or null if not server or prefab not found
ToString()
Returns the prefab name as a string.
public override string ToString()
Returns
Operators
implicit operator string(PrefabRef)
Implicitly converts PrefabRef to its underlying prefab name string.
public static implicit operator string(PrefabRef prefab)
Parameters
prefabPrefabRefThe prefab reference to convert.