photonView.owner.name not working

I have a multiplayer game, I display player names with a 3d text.

Using photonView.owner.name works when the player opens up the app and connects for the first time in that session. All player names are displayed correctly. Once you disconnect and try to join a different room, you can only see your own name and everyone else's names are "No name".

Here is how my script works the important parts:
//StartMainMenu
function Start (){

if(PlayerPrefs.getString("UserName")=="" || PlayerPrefs.getString("UserName")==" "){
PlayerPrefs.SetString("Username","No name");
}
PhotonNetwork.playerName=PlayerPrefs.GetString("UserName");

}
//EndMainMenu

//StartDisplayName
function Start(){

tm=gameObject.GetComponenet(TextMesh);
tm.text = photonView.owner.name;

}

//EndDisplayName

//StartDisconnect

function Exit(){

PhotonNetwork.DIsconnect();
Application.LoadLevel("MainMenu");

}
//EndDisconnect

//StartIfHostChangeDisconnect

function Start(){

roomCreator = PhotonNetwork.masterClient;
//way earlier I initialize roomCreator as the person who first connects to the room

}

function Update(){

if(roomCreator!=null){

if(!ReferenceEquals(roomCreator, PhotonNetwork.masterClient)){

roomCreator=null;
PhotonNetwork.DIsconnect();
Application.LoadLevel("MainMenu");

}

}

//kicks out all players from lobby if master changes
}

//EndIfHostChangeDisconnect

I know for a fact that it's not going into the if in the main menu, other wise my own name would also appear as "No Name".

Comments

  • I will try to look into this. If at all, it will be a minor problem due to the order in which we process things.
    Some info for you to check:
    You only know the owners of GameObjects while you are in a room. When you leave and return to a lobby, it's not known anymore.
    In worst case, you might be instantiating the game objects before we synced the names. In some cases, PUN has to do this after the join.

    Which PUN version are you using?
  • I will try to look into this. If at all, it will be a minor problem due to the order in which we process things.
    Some info for you to check:
    You only know the owners of GameObjects while you are in a room. When you leave and return to a lobby, it's not known anymore.
    In worst case, you might be instantiating the game objects before we synced the names. In some cases, PUN has to do this after the join.

    Which PUN version are you using?

    I am using v 1.25.2 (03. April 2014), can I force pun to sync names before spawning? I also make sure I do

    PhotonNetwork.playerName=PlayerPrefs.GetString("UserName");
    before spawning the GameObject...

    I have another question, is there a tutorial to show how to get PUN and Unity working on a local network without the need of a server?
  • The player name is synced as early as possible, if you set it before you join a room.

    There is no way to run PUN without a server. You can run a Photon Server yourself in a local net.
    There is a Photon Server SDK and a Photon Server Redistributable package. Both on our download pages:
    https://www.exitgames.com/OnPremise/Download
  • I made sure that I set the name before joining the room. Like I said it works for the first join of the session.then if it's the second join that session it shows "no name" for everyone but you.
  • So is there a solution to my problem? I set the name before joining the server...
  • Sorry for letting you wait for a reply. The Easter Holidays and some other tasks took some time.

    Which platform and which Unity version do you use?
    I found that Unity 4.3.4 has a bug on iOS which could lead to this issue. If you use that version and iOS disable "code stripping" in the player settings and give it a try.
    I checked Unity 3.5.7 and 4.6 and both exports work fine. I am waiting for a response by Unity on this topic (really fresh bug)...
Sign In or Register to comment.