Clarification about PhotonNetwork.playerName

Hello everyone! At first, a little disclaimer. I am planning to use PUN (with photon cloud) in my project as a most reliable and easy to use multiplayer backend. I am moving form combination of Google Play multiplayer and Unity networking, which was proven unusable in serious projects. I will be asking a series of questions for which I didn't find the answers in docs or somwhere else (forum, stackoverflow, unity answers). Don't get me wrong, I will be glad if I'm mistaking, and the answers are obvious or easy to find. Anyway, please point me in right direction and please don't leave any of this questions unanswered.

My first question is about playerName. As stated in the docs, "setting the name will automatically send it, if connected". Does this name guaranteed to be unique among all players of my game? If yes, is there a way to handle the situation when we set the name that already exists? If no, what's the purpose of FindFriends, where we request a list of friends by their names (What if we have a friend named "Player" and there are also 1000 players named "Player")?


  • Hi diablo23q.

    Yes, that name has to be unique and you as the app-programmer have to ensure this uniqueness. A possible way to do this is to let the player choose a name and then append that name with a unique id. You would then internally use that full name including that unique id as the players identifier, while you would cutoff that unique id when you need a displayname to display on screen. Another way would be to just generate and store some unique id and pass that as playername to Photon, completely independent of whatever name the player chooses for himself.
  • Thanks a lot! I think I'll implement the solution with appending unique id.