Multiplayer Advanced

In multiplayer experiences, each player's avatar must be visible to all other players with synchronized position, animation, and lip sync. This lesson covers avatar instantiation, state synchronization, and voice chat integration using popular Unity networking frameworks.

Networking Framework Options

FrameworkBest ForKey Feature
Photon PUN 2Room-based games, social appsEasy setup, cloud-hosted
Unity Netcode for GameObjectsFirst-party Unity projectsDeep Unity integration
MirrorOpen-source, self-hostedCommunity-driven, flexible

Avatar Synchronization

The key challenge is that avatars are loaded dynamically from Ready Player Me URLs, not from prefabs in the project. You need to:

  1. Share the avatar URL

    When a player joins, send their Ready Player Me avatar URL to all other clients via a network RPC or custom property.

  2. Load remotely

    Each client loads the avatar from the URL independently. Use the SDK cache to avoid redundant downloads.

  3. Sync transforms

    Use NetworkTransform or Photon Transform View to synchronize position and rotation at a fixed tick rate.

  4. Sync animations

    Synchronize Animator parameters (Speed, Direction, etc.) across the network. Use NetworkAnimator or custom RPCs for state changes.

Voice Chat Integration

For social and meeting applications, integrate Photon Voice or Vivox for spatial voice chat. Route the voice audio through the lip sync system so remote players see lip movement matching the speaker's voice.

Bandwidth Tip: Do not synchronize individual blend shape weights over the network. Instead, send the active viseme index (a single byte) and let each client apply the blend shapes locally. This reduces bandwidth by over 90% compared to syncing all 15 weights.