Table of Contents

Class PrefabRef

Namespace
S1MAPI.Core
Assembly
S1MAPI_Mono.dll

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

name string

Exact prefab name in FishNet registry

Properties

Name

The prefab name as registered in FishNet

public string Name { get; }

Property Value

string

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:

  1. Instantiates the prefab as inactive to prevent Awake() from running with uninitialized network state
  2. Initializes any GUID fields to prevent parse errors (fixes issues with prefabs like ATM)
  3. Spawns the object on the FishNet network, assigning it a network ID
  4. 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

parent Transform

Parent transform (set before spawn)

localPosition Vector3

Local position relative to parent

localRotation Quaternion

Local 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

string

Operators

implicit operator string(PrefabRef)

Implicitly converts PrefabRef to its underlying prefab name string.

public static implicit operator string(PrefabRef prefab)

Parameters

prefab PrefabRef

The prefab reference to convert.

Returns

string