Search Unity

Third Party Photon - Newbie Questions

Discussion in 'Multiplayer' started by MadMunky, Jan 22, 2015.

  1. MadMunky

    MadMunky

    Joined:
    Jan 3, 2015
    Posts:
    10
    Im just starting out with Photon after watch the FPS live lesson that was done.

    My game though is a bit different, what I do is I have a GameObject which has a script which is run at start and this creates all my levels from prefab parts so my first question is, my prefabs that need it have a PhotonView attached but as the object are not on the scene to start with and only called during start-up I believe these causes problems with the ViewID so how should I be doing this, should my call be a PhotonNetwork.Instantiate to create all the objects?

    This leads on to my next question, I'm doing a Dungeon Crawler so objects like doors/items/monsters need to be synced across the network so when Player 1 opens the door Player 2 sees it. My thought was to attach a PhotonView to each Object and have a RPC call for something like GameObject.OpenDoor() so it fires on all clients, is this the correct way or am I doing all this wrong?

    I said i'm a newbie so if there is anything I should be reading/looking at please let me know :)

    Here's a video so you can see the type of game


    Thanks for any help :)
     
  2. MadMunky

    MadMunky

    Joined:
    Jan 3, 2015
    Posts:
    10
    I've been trying to find out more on how I do this and I believe what I need to do is use PhotonNetwork.InstantiateSceneObject which I am now doing and is fine on the master client but I dont see the action happen on the client, all the doors are created and I see the RPC call fire but you dont see the action taken on the client :(

    Any ideas, I cant find much on how all this should be done
     
  3. MadMunky

    MadMunky

    Joined:
    Jan 3, 2015
    Posts:
    10
    Ignore that found my problem, I was check for a isMine on the object :)
     
  4. MadMunky

    MadMunky

    Joined:
    Jan 3, 2015
    Posts:
    10
    Hopefully my last question on the subject, all is working fine when two users are connected. The problem is even though im doing a buffered RPC if the user leaves the game and rejoins it does not get the current state of all the objects so if a door was opened after the game started but before the player joined it will show as closed still as the player was not connected to get the RPC event.

    How do you normally cater for that?
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    RPCs are conntected to the player. When a player leaves, the RPCs are cleaned up.
    If it's about doors, use room.SetCustomProperties() and a key per door. Make the keys (strings) as short as possible.
    The benefit of properties: It stores if the door is open or not. It does not buffer the history of being opened/closed (like buffered RPCs).
    Also, room properties are not cleaned up when a player leaves (but when the room is empty).

    PUN and the Photon Cloud are not built for persistency. There is a technical limit at some point for buffered events and vast amount of properties. Test carefully your worst case scenario.

    Nice video! :)
     
  6. MadMunky

    MadMunky

    Joined:
    Jan 3, 2015
    Posts:
    10
    Thanks tobiass,

    I managed to work this out in the end, the way I do it is have a DoorDetails script which has all the setting like isOpen etc.. then I serialize it and send it over the network that way as the players join and get the scene objects they are all configured correctly.

    Not sure if this is the right or wrong way but its working :)