Kanda Players 0.7.0
Loading...
Searching...
No Matches
Avatars

For every player spawned in the world, we need to show its avatar as a visual representation in the scene. This page explains how to set up the avatar for local and remote players, as well as different avatars per platform.

Avatar Entity

The approach used in this package is spawning the avatar entity as a separate entity from the player part entity. This makes it easier to customize the avatar prefab without affecting the player part entity. The prefab can be an entity prefab without custom component setup in the editor.

Avatars are spawned for all player parts, both local and remote. However, for remote player parts that have a local counterpart (i.e., have GhostOwnerIsLocal enabled), the avatar spawning is skipped as the local player part is responsible for spawning the avatar.

Setup Avatar Spawner

To set up the avatar spawner, we need to add the AvatarPartSpawnerAuthoring component to the prefabs that represent the local and remote player part entities based on platforms:

  • LocalPlayerPcHead
  • LocalPlayerVrHead
  • RemotePlayerPcHead
  • RemotePlayerVrHead
  • etc. (local and remote player parts separated by platforms)

Currently, these prefabs are located in /Runtime/Prefabs/Players/Local and /Runtime/Prefabs/Players/Remote folders.

Then, set up the Prefab field in the AvatarPartSpawnerAuthoring component with the avatar prefab that you want to spawn. We have an example in the folder /Runtime/Prefabs/AvatarHead.prefab.

Avatar Attachment

We use the Attachable component to connect avatars to their corresponding player parts.

Here's how it works:

  1. When an avatar is spawned, an Attachable component is added to it.
  2. The Attachable component is set up with a reference to the player part entity that it should be attached to.
  3. This attachment ensures that the avatar will follow the movement and rotation of the player part it's attached to.

Spawning Process

The AvatarSpawnClientSystem handles the spawning of avatars:

  1. It finds all entities with an AvatarPartSpawner component.
  2. For each of these entities:
    • If the entity has GhostOwnerIsLocal enabled, it skips spawning (as mentioned earlier).
    • Otherwise, it spawns the avatar prefab specified in the AvatarPartSpawner.
  3. After spawning, it adds the Attachable component to the avatar, setting the player part as the owner.
  4. It also adds a Movable component to the avatar which is used by Attachable.
  5. The avatar entity is added to the LinkedEntityGroup of the player part, ensuring it's destroyed when the player part is destroyed.

Considerations for Developers

  • When creating avatar prefabs, keep in mind that they will be attached to and follow the player parts. Design them accordingly.
  • The avatar's transform will be controlled by the attachment system, so any custom positioning should be done relative to the attachment point.
  • If you need custom behavior for avatars, consider adding components to the avatar prefab and systems that work with those components.
  • Remember that avatars are client-side representations. Any gameplay-critical logic should be handled on the player part entities, not the avatars.