Kanda Players 0.7.0
|
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.
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.
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:
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
.
We use the Attachable
component to connect avatars to their corresponding player parts.
Here's how it works:
Attachable
component is added to it.Attachable
component is set up with a reference to the player part entity that it should be attached to.The AvatarSpawnClientSystem
handles the spawning of avatars:
AvatarPartSpawner
component.GhostOwnerIsLocal
enabled, it skips spawning (as mentioned earlier).AvatarPartSpawner
.Attachable
component to the avatar, setting the player part as the owner.Movable
component to the avatar which is used by Attachable
.LinkedEntityGroup
of the player part, ensuring it's destroyed when the player part is destroyed.