How To Dynamically Replace Your Character
NOTE: There is a component in the UI package called "UICharacterSwitch" that is used to provide a UI option to dynamically swap your character at runtime.
You can simply call the RequestSpawnCharacter on the EMI_NetworkManager and it will replace any existing characters if any. There may be some additional things you want to do so I made a little script below to show you a little more advanced usage chase:
#region Properties
[SerializeField, Scene, Tooltip("Move characters to this scene if you're adding the character for the first time. Otherwise this is will just use the scene that is currently there.")]
protected string defaultScene;
protected ClientConnection owningConn = null;
protected bool waiting = false;
#endregion
[Client]
public virtual void SwitchCharacter(GameObject switchTo)
{
if (waiting) return;
owningConn = ClientUtil.GetMyClientConnectionObject();
if (!owningConn) return;
waiting = true;
owningConn.OnPlayerCharacterChanged += OnPlayerCharacterSwitched;
EMI_NetworkManager.instance.RequestSpawnCharacter(
switchTo.name, // The gameobject you want to switch to, you need to make sure this is in the "Registered Spawnable Prefabs"
PointsUtil.PointType.Self, // Will spawn the character in the same place the call was made from
(owningConn.playerCharacter) ? owningConn.playerCharacter.scene.name : defaultScene,
"",
(owningConn.playerCharacter && owningConn.playerCharacter.GetComponent<Team>()) ? owningConn.playerCharacter.GetComponent<Team>().teamName : "",
"",
false
);
}
protected virtual void OnPlayerCharacterSwitched(GameObject newChar)
{
if (newChar != null) // Do a null check because there is a brief moment where the character is null
{
owningConn.OnPlayerCharacterChanged -= OnPlayerCharacterSwitched; // only do this once so remove it when this is finished
newChar.GetComponent<vThirdPersonInput>().FindCamera(); // Make the main camera switch to the character
waiting = false; // All the "SwitchCharacter" function to be called again
owningConn = null; // Make fresh checks be performed every time
}
}