Skip to main content

Player Location

1. Overview

The PlayerLocation component defines a physical spawn point or anchoring slot for a networked player within the scene. It works hand-in-hand with the SessionPlayerManager to manage where users appear.

Because it inherits from NetworkIdBehaviour, each spawn location has a unique Network ID, allowing the server and clients to reference exact locations safely across the network.


2. Component Structure

2.1. Properties

Figure 1: PlayerLocation in the Unity Inspector.

  • Current Player (NetworkPlayer): A reference to the player currently occupying this location. If null, the location is considered empty.
  • Is Empty (bool): A getter property that returns true if no player is currently assigned.

2.2. Visual Debugging

To assist with level design, the component implements OnDrawGizmosSelected. When selected in the Unity Editor, it draws a wireframe cube representing a bounding box of roughly 1.7 meters in height, helping developers visualize the space a player will occupy.


3. Core Methods (API)

  • public void SetPlayer(NetworkPlayer player)

    • player: The NetworkPlayer instance representing the user that will occupy this space. Assigns the provided player to this location, parenting the player's transform to this location's transform and zeroing out the local position and rotation.
  • public void SetSelfPlayer(NetworkPlayer player)

    • player: The local NetworkPlayer instance. A variant of SetPlayer often used locally to ensure the local user is anchored correctly to the spawn point.
  • public void ClearPlayer() Unparents the current player and marks the location as empty, freeing it up for other users.