How to create a custom skin for each player

Options
Hi, I am new to Photon. I have a playerPrefab which is simply a game object with some scripts (but no skin).
I want to instantiate the player on all clients and then set the correct skin which is either a wizard skin prefab or a warrior skin prefab.
I use custom properties to set the skin name and that works.
On the player object, I have this piece of code:
void OnPhotonInstantiate( PhotonMessageInfo info )
{
	Debug.LogError("Skin: " + info.sender.CustomProperties["Skin"]  );
	if ( PhotonNetwork.isMasterClient )
	{
		GameObject skin = (GameObject)PhotonNetwork.Instantiate      (info.sender.CustomProperties["Skin"].ToString(), Vector3.zero, Quaternion.identity, 0, null);
		skin.transform.SetParent( transform, false );
		skin.transform.localPosition = Vector3.zero;
		skin.transform.localRotation = Quaternion.identity;
		}			
	}
The result is as follows. There are 2 players. One has the warrior skin property and the other has the wizard skin property.
On MasterClient all is well. Each player has the correct skin, it is parented correctly and the rotation and position is correct.
On the remote client, one skin got create (let's say for warrior), in the centre of the world and it is not parented. The other skin (wizard) never got created.

What should I do to instantiate the skins, set their parents and position/rotation correctly on all clients?
Because I am a new, I would appreciate sample code if possible. Thanks for your help!

Comments

  • Hi @Koran,

    how many different skins are there in your game? You have given us an example with just two different skins. If there are no more additional skins, you can simply create two prefabs (one representing the warrior, the other representing the wizard) and instantiate one of them based on your 'role' in the game, e.g.:
    
    public void OnJoinedRoom()
    {
        if (PhotonNetwork.isMasterClient)
        {
            PhotonNetwork.Instantiate("Warrior", Vector3.zero, Quaternion.identity, 0);
        }
        else
        {
            PhotonNetwork.Instantiate("Wizard", Vector3.zero, Quaternion.identity, 0);
        }
    }
    
    If there are more different 'characters', it might be good idea to have a unique prefab for each of them, since instantiation might be is easier than trying to 're-skin' the game objects.
  • Koran
    Options
    Hi Christian, thanks for your suggestion. However, I do have many different skins (much more than 2). In addition, I want to support accessories such as different staff, swords, etc. It becomes impossible to have a prefab for all possible permutations. Hence the idea of sending the skin/accessories via custom properties.
    Still open to suggestions on how to solve this. Thanks!
  • Hi @Koran,

    the player's custom properties may be one option to go with. Another is the usage of RPCs since your characters already have a PhotonView component attached to them. For example this one:

    pView.RPC("SwapWeapon", PhotonTargets.All, "Epic Sword");

    and
    public void SwapWeapon(string weaponName)
    {
        if (weaponName == "Epic Sword")
        {
            // Equip matching weapon
        }
    }
    Names can also be replaced by unique IDs making it maybe easier to deal with. This can be also applied to other components or properties of the characters, you just need something to address it as seen in the example above.
  • AmiGarcia
    Options
    Hi there!

    I've the same question as @Koran. I've a game where it's possible to choice different accessories for your character, such as sunglasses, ties, hats... It's the same prefab, but with different Sprites in those objects.

    I want to know how can i do to make everyone see those skins in the right player?

    Thanks in advance!