Skip to content

Network Object Spawner

Esteban Maldonado edited this page Sep 21, 2022 · 4 revisions

This class lets you spawn a new GameObject on the active networked session. There are 2 main methods which are SpawnNewNetworkObject and SpawnNewNetworkObjectChangeOwnershipToClient. The 2nd one is used when spawning the player spaceships for each connected player/client.

List of methods and overloads:

SpawnNewNetworkObject:

  • Prefab: The prefab to spawn.
  • DestroyWithScene: Defaults to true, set if you one the prefab to destroy with the scene.

SpawnNewNetworkObject:

  • Prefab: The prefab to spawn.
  • Position: Set the position to spawn the prefab.
  • DestroyWithScene: Defaults to true, set if you one the prefab to destroy with the scene.

SpawnNewNetworkObject:

  • Prefab: The prefab to spawn.
  • Position: Set the position to spawn the prefab.
  • Rotation: Set the rotation of the spawned prefab.
  • DestroyWithScene: Defaults to true, set if you one the prefab to destroy with the scene.

SpawnNewNetworkObjectChangeOwnershipToClient:

  • Prefab: The prefab to spawn.
  • Position: Set the position to spawn the prefab.
  • newClientOwnerId: The id of the client who will own the object.
  • DestroyWithScene: Defaults to true, set if you one the prefab to destroy with the scene.

Using these methods, you instantiate a prefab on the hosting server and replicate it on all clients. More information on object spawning here.