Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party Trouble with Player Instantiate Photon

Discussion in 'Multiplayer' started by tookydo, Feb 8, 2015.

  1. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    The player and all the other players spawn correctly and they can move and there position is updated and all that but there is just one problem.

    If a player is instantiated before another player joins the room, the player that wasn't joined to the room before the other spawned their player wont see the first player.

    To make this easier to understand I will use and example:

    This is what happens when they are both present in the room

    Player 1, Player 2
    Player 1 creates and joins the room
    Player 2 joins the room
    Player 1 and 2 spawn player
    Everything works fine

    This is what happens when Player 2 isn't in the room when Player 1 Spawns the player

    Player 1 creates and joins the room
    Player 1 Spawns Player
    Player 2 joins the room
    Player 2 spawns player
    Player 1 can see Player 2 but Player 2 can not see Player 1

    What could I be doing wrong. Could it be my Smooth Network Movement Script? How and when I instantiate?
    Any help would be greatly appreciated!
     
  2. pSeth

    pSeth

    Joined:
    Mar 11, 2014
    Posts:
    10
    Use RPC buffer when instantiating so anything that was spawned before a player joins will be there
     
  3. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    @pSeth How am I supposed to do that?
     
  4. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    How would i do that?
     
  5. pSeth

    pSeth

    Joined:
    Mar 11, 2014
    Posts:
    10
    networkView.RPC ("SpawnPlayer", RPCMode.All, null); Would be changed to networkView.RPC ("SpawnPlayer". RPCMode.Buffer, null);
     
  6. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    How would that translate to Photon?
     
  7. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    wait nevermind I got it, thanks
     
  8. pSeth

    pSeth

    Joined:
    Mar 11, 2014
    Posts:
    10
    I don't use photon, sorry! But glad you got it!! Keep it up man!!!
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    Please post the answer :)
     
  10. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    After trying it didn't work. I use photontargets.allbuffered and the other player saw the first player fine but on the first players screen there was 2 of him.
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
  12. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Do you use PhotonNetwork.Instantiate ? With this, your players should at least see each other.

    Can you show your "Spawn" function ? And how (and where) do you call it ?
     
  13. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75

    Attached Files:

  14. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    I had it as PhotonTargets.AllBuffered and it wasnt working so I was just trying something, It also originally was an RPC but I was going off the Marco Polo Tut as Tobiass suggested.
     
  15. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    So I am having a similar issue.

    I want to do the following the first player creates the room he loads the scene. Now he creates the car for that player. I now open the room, a second player joins, he creates his car, but didnt create the other players car (because it happened in the past).

    Okay so I tried.

    PUNRaceManager.cs
    Code (CSharp):
    1.  
    2.  
    3.    void Start (  )
    4.     {
    5.  
    6.         //if(PhotonNetwork.isMasterClient)
    7.         {
    8.             PhotonView pv = gameObject.GetComponent<PhotonView>();
    9.             if(pv)
    10.             {
    11.                 pv.RPC("CreateCarRPC",PhotonTargets.AllBuffered);
    12.             }
    13.         }
    14.  
    15.         //CreateCar();
    16.  
    17.     }
    Now what happens is that I load the first car -- when the master client creates the room. The second car is created when the client joins the room, but he also spawns another car for the first the player.

    If I uncomment the isMasterClient line of code I get the following error. I assume its because the photonview is owned by the scene.
     
    Last edited: Jan 4, 2016