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! Your search result can be found below. Plus, we offer support via these channels:

Try Our

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.

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 do a synch a name change?

2019-10-25 18:03:28

I want o change the names of certain gameobjects during runtime, does anyone know how to synch this?


2019-10-25 19:11:19

Maybe with an RPC function ? have you tried that ?

2019-10-26 19:24:10

I have tried it, but the name change does only goes through on my client. Not on the other one.
I have tried to setup a onphotonserializeview to sync it, but to no avail

2019-10-29 09:07:07

Hi @BlitzBurn,

I'm interested to know why you need this?
What information does the GameObject's name hold?

RPC or RaiseEvent or PhotonView serialization are different ways to do this.
You could share more details about what you have tried, code snippets.

2019-10-29 18:36:59

I am currently developing a small scale multiplayer game using photon as a school project.
We choose our own projects, and I originally intended to use Unet as Photon had not been part of the cariculum, but switched after Unet started causing problems.

I originally wanted to know how to switch names of gameobjects since another function depended on it. The function itself was used to ensure that the projectiles fired by the player would not hurt the player that fired it. The projectile would compare recieve the name of the player that fired it and then compare that name to whatever it collided with to determine if it should deal damage or not.
As of right know I have scrapped the whole system for the sake of my own sanity and for the sake of time.

This is the code that would recieve the players username in the login scene:

  public void UserNameInput_OnClick()  
        //Generates a hashtable to store the name input  
        ExitGames.Client.Photon.Hashtable _customName = PhotonNetwork.LocalPlayer.CustomProperties;

        //Takes the text in the input field and puts it in a string  
        userName = userNameInput.text.ToString();

        //saves the input in the hashtable  
        _customName["CustomPlayerName"] = userName;  
        PhotonNetwork.LocalPlayer.CustomProperties = _customName;  
         //This line was just used for testing the code   
        string SavedUsername = (string)PhotonNetwork.LocalPlayer.CustomProperties["CustomPlayerName"];  

//This code was attached to the player prefab and would load the name in the gameplayscene  
    private void ChangeName()  
        newName = (string)PhotonNetwork.LocalPlayer.CustomProperties["CustomPlayerName"];         = newName;          

I believe the Change Name() method was called correctly, although the line that did call it is long gone.

The exact issue was that every instance of the player prefab would recieve the new name that was saved, but this name would not be synched with the other clients. If user #1 entered the name BlitzBurn and user #2 entered JohnTube, #1 would see that both players were named BlitzBurn while #2 would see that both players were named JohnTube.

There were more variations of the code, as I tried several thing over the course of several days, but all of them had pretty much the same result.

2019-10-31 12:44:01

Hi @BlitzBurn,

  1. Player.CustomProperties should be used as "read-only". Do not modify it directly. Instead, use Player.SetCustomProperties() method to add, modify or remove custom actor properties.
    public void UserNameInput_OnClick()  
        //Generates a hashtable to store the name input  
        ExitGames.Client.Photon.Hashtable _customName = new ExitGames.Client.Photon.Hashtable(1);  
        //Takes the text in the input field and puts it in a string  
        userName = userNameInput.text;

        //saves the input in the hashtable  
        _customName["CustomPlayerName"] = userName;  
  1. Photon already has a built-in Player.Nickname.
Back to top