Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Photon PUN 2 string issues

Discussion in 'Connected Games' started by Foestar, Aug 23, 2019.

  1. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    316
    So I'm picking up PUN 2 pretty easy so far but I'm struggling with a small issue involving a string. I have it so each player has a string for firstPlace, secondPlace, and thirdPlace. I also have a string called nameToBeSent. This string is given the player's nickname/alias like so.

    Code (CSharp):
    1. nameToBeSent = PlayerAliasMenuControl.PlayersAlias;
    Then I send the RPC to everyone with the string inside it like so.

    Code (CSharp):
    1. base.photonView.RPC("FirstSent", RpcTarget.All, nameToBeSent);
    So this is where the problem begins. I then make a text field equal the place, in this case 1st, along with the name. This much does work. The next part however doesn't and I can't seem to figure out why it wont no matter what I try. I'm trying to make it update so the firstPlace string for every player equals that same name so they register that a person is in that place. However, if I make it equal to it doesn't show, and if I add/equal it again it doesn't show. What am I doing wrong?


    Code (CSharp):
    1. [PunRPC]
    2. public void FirstSent(string nameToBeSent)
    3. {
    4. FirstPlace.GetComponent().text = "1st: " + nameToBeSent;
    5. firstPlace += nameToBeSent;
    6. }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,303
  3. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    316
    Negative, have not solved the issue yet. Setting nicknames hasn't been a problem nor showing them to this point. It's sending strings specifically that has been the issue. I can get the string to be received and set a text field based off it. But making all other clients/players register/update that said string is where I am finding problems.

    I'm thinking at this point the issue isn't so much that it's not being received, but rather not updating on every player entity in the scene. I'm backing this because when a player passes the finish line they show up as done and update their own field, but no one else gets the update.

    This is weird to me as it's a generalized RPC that should be activated on ALL of the clients/player entity's. I took a day or two off to think it through and just spent the last 2 days trying again to no avail. Also read through both links and documentation multiple times. I'm sure I'll figure it out, but no idea what I'm doing wrong atm. I'm sure it's probably something minor and stupid though as it usually is.
     
  4. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    316
    I ended up working around the issue. It was as I thought, the string was being updated awkwardly between the player prefabs in a way it wasn't reading despite using photonview ismine being used. My workaround was to place the string in an object that each player only has 1 of rather than 2-8 player prefabs. It actually ends up better as I can reuse the strings 1st, 2nd and 3rd for other game modes as well.
     
unityunity