Respawn Player
ObjectNet provides built-in tools to respawn players dynamically. This is especially useful in scenarios such as:
Handling player death and revival
Resetting players during game state changes
Reloading or transitioning between scenes
On the Server
When acting as the server, you have full control over all player objects and can trigger respawns directly.
Respawn the Local Server Player
//you can call it anywhere
NetworkManager.Instance().RespawnServerPlayer();
//or if you want more control over spawn position and rotation
NetworkManager.Instance().SpawnPlayer(null, position, rotation);
Destroys the current server player object (if it exists) across all clients.
Spawns a new player instance using the prefab and spawn logic defined in
NetworkManager
.
On the Client
Clients can request a respawn from the server. This is a permission-based operation — the server decides whether to approve and execute the respawn.
Request Respawn (While Player is Alive)
//calling it from inside the Active Player NetworkBehaviour
NetworkManager.Instance().RequestPlayerRespawn(this.GetNetworkElement());
//or any where by using
INetworkElement playerElement = NetworkManager.Instance().GetLocalPlayerElement<INetworkElement>()
NetworkManager.Instance().RequestPlayerRespawn(playerElement);
Sends a request to the server to destroy the current player and spawn a new one.
Supports optional parameters to customize the spawn location and rotation:
//calling it from inside the Active Player NetworkBehaviour
NetworkManager.Instance().RequestPlayerRespawn(
this.GetNetworkElement(), null, newPosition, newRotation
);
Respawn When Player is Already Destroyed
If the player object was already destroyed (e.g., during a scene load), you can Spawn as how you will in Spawn Player Manually (this works for both host and clients)
//you can call it anywhere
NetworkManager.Instance().SpawnPlayer(null, position, rotation);
//Note: make sure the player is destroyed before calling SpawnPlayer or else
//you will have dublicates
This is typically used in cases where:
All players are removed during scene transitions
Players is destroyed and you need to instantiate it
Last updated