How do a synch a name change?

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

Best Answer

Answers

  • daaxee
    Options
    Maybe with an RPC function ? have you tried that ?
  • BlitzBurn
    Options
    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
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    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.
  • BlitzBurn
    BlitzBurn
    edited October 2019
    Options
    @JohnTube
    Hi,
    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
     [PunRPC]
        private void ChangeName()
        {    
        
            newName = (string)PhotonNetwork.LocalPlayer.CustomProperties["CustomPlayerName"];       
            gameObject.name = 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.