How to create a custom skin for each player

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to create a custom skin for each player

Koran
2017-02-11 18:51:18

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

[Deleted User]
2017-02-13 13:59:55

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
2017-02-13 19:36:02

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!

[Deleted User]
2017-02-16 15:42:13

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
2018-01-23 14:22:49

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!

Back to top