Switching Player Object to a new Prefab During Runtime

Options
Hi All! First time post here. I'm trying to find an efficient way of switching characters during runtime. Each character has different hitboxes/scripts and it'd be somewhat messy and painful to have to switch out each component when a player wants to change heroes.

I haven't tested this because I'm not at home at the moment, but is it possible to have every client instantiate a new object, swap the photonView and its ID to the new player object, and destroy the old object? Is that even the correct approach? Would this mess up the PhotonNetwork.playerlist? Is there a better way to seemlessly swap player objects without disrupting any player lists / gameplay?

Thanks in advance!
Mr.Muffles

Comments

  • Hi @MrMuffles,

    [...] but is it possible to have every client instantiate a new object, swap the photonView and its ID to the new player object, and destroy the old object?


    I guess the best way is to destroy the current object first, before instantiating a new one, because this seems to be the 'cleanest' way. This also avoids reusing existing PhotonView components, so you shouldn't run into any View ID related issues. If switching the character happens while an ongoing respawn phase, no one else will notice.

    Would this mess up the PhotonNetwork.playerlist?


    The PlayerList is not (directly) connected to the instantiated player objects. The PlayerList simply contains each connected client in the room. So instantiating or destroying player objects don't have any influence on the PlayerList. There is one exception to this: If you are using the TagObject field of a PhotonPlayer object (those are the elements of the PlayerList), you would have to update this field accordingly.