Spawn Player Manually

By default, ObjectNet automatically spawns the player GameObject when a client connects. However, you can override this behavior and take full control of the player spawning process.

Manual Player Spawning

To manually spawn the player, enable the "Manually Spawn" option in the NetworkManager settings. Once enabled, you are responsible for calling the spawn logic through code when you need it.

// Call this from anywhere in your code when you're ready to spawn the player
NetworkManager.Instance().SpawnPlayer();

This will:

  • Spawn the Player Prefab assigned in the NetworkManager

  • Use the Spawn Position specified in the NetworkManager

  • Synchronize the spawn across all clients

Custom Prefab or Position

You can also override the prefab and/or position, rotation programmatically:

// // Uses prefab passed in code, but still requires the position to be set in NetworkManager
NetworkManager.Instance().SpawnPlayer(this.playerPrefab);

// Full control: no need to set anything in NetworkManager
NetworkManager.Instance().SpawnPlayer(this.playerPrefab, position);
NetworkManager.Instance().SpawnPlayer(this.playerPrefab, position, rotation);

//or set the player prefab to null to use the player prefab set by NetworkManager
NetworkManager.Instance().SpawnPlayer(null, position, rotation);

These overloads let you:

  • Spawn a custom instead of the default one in the NetworkManager inspector

  • Choose custom spawn positions and rotations per player

  • Skip relying on NetworkManager settings entirely

Note: You can spawn the player multiple times so make sure it is destroyed before spawning it again or else you will end up with duplicate's

Last updated