Search Unity

Third Party A few Photon-related problems

Discussion in 'Multiplayer' started by Simba, Jul 6, 2013.

  1. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    Hi, first of all, I apologise if this is in the wrong section. I'm not sure if I'm declaring things incorrectly or Photon's causing issues.

    I'm using PN.CreateRoom(), and trying to include a hashtable of important information (like the name of the world it's using, etc). I use the following code:
    Code (csharp):
    1.  
    2. var serverInfo : String[];
    3. print(WorldURL+":"+WorldName); // To check they exist
    4. PhotonNetwork.CreateRoom(serverName, !serverHidden, true, 9, {"isPassworded" : ((serverPassword != "") ? "1" : "0"), "URL" : WorldURL, "WorldName" : WorldName}, serverInfo);
    This runs, shows no errors. Then I use:
    Code (csharp):
    1.  
    2. var data : RoomInfo[] = PhotonNetwork.GetRoomList();
    3. for (var game in data) {
    4.     serverData = game.customProperties;
    5.  
    6.     print(serverData["WorldName"]); // prints "NULL"
    7.     var serverWorld : String = serverData.Item["WorldName"];
    8.     var serverWorldURL : String = serverData.Item["URL"];
    9.     var isLocked : boolean = !(serverData.Item["isPassworded"] == "0");
    10.            
    11.     GUILayout.BeginHorizontal();
    12.     GUILayout.Label(game.playerCount.ToString(), GUILayout.Width(40));
    13.     GUILayout.Label(game.name);
    14.     GUILayout.Label(serverWorld);
    15.     GUILayout.EndHorizontal();
    16. }
    17.  
    Everything except "game.customProperties" works. The "customProperties" contains nothing. Every item it's supposed to contain returns "NULL".

    Why is this happening and how can I fix it? :confused:

    -----

    Another question:

    I have an object with a script attached that's in the main "Game" scene (i.e., what every player loads after the lobby) that I need every player to connect to and use (everyone has to send and receive RPCs via it). When it sends an RPC to a new player, the player returns an error that says that the viewID of the object (999) doesn't exist, and ignores the message. Given that it has loaded the scene and thus has a copy of the object with the same viewID, how is this possible? Is it a limitation of Photon that says that all PhotonViews must have only one controller?

    Thanks in advance!
     
    Last edited: Jul 6, 2013
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    You can solve the first issue by defining the list of properties you need in the lobby. It's a string[] and you just pass in the names of those properties.
    We split it this way, cause most games have some matchmaking-relevant values and many values that are interesting only in-game.
    Note: Sending "0" or "1" should be replaced by a bool value (true or false).


    I don't know how you create the second issue.

    Do you use a lot of PhotonViews? I never had a view ID 999 just after loading...
    The number of GameObjects per player is limited to 999. While you could work around this limit, in most cases it makes more sense to reduce the number of objects that are networked to save bandwidth, etc.

    And yes, all PhotonViews have only one owner. It's either the scene (when a scene contains a PV on load) or the player who created the GO from prefab.
     
  3. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    Ah, ok. I thought I needed to send the data in the hashtable :roll: thanks!

    And it's not set at runtime. I set the viewID to 999 from the Scene view to prevent it getting in the way of players joining.

    Given that PhotonViews have only one owner, and in my case it's the scene, is it still possible for everyone to send and receive RPCs through it?

    Thanks again for your reply!
     
  4. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    <duplicate post, sorry>
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    You can always call RPCs on any PhotonView, no matter who owns it.

    You should be careful calling RPCs on other players' objects, if your game destroys GameObjects and PhotonViews. The owner can do this anytime - even while someone else calls an RPC on it simultaneously. Due to lag, the RPC will then be executed on some machines (on the originating machine it's called immediately) but not on others (the owner destroyed the GO, so it can't execute RPCs anymore).

    That's an edge case to be aware of but scene PVs should be save.

    Also, you don't need to arrange view IDs. This is done automatically. Scene views have their own ID range, as all players have theirs. It will only clash when you use > 999 IDs at the same time per scene or player.
     
  6. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    Ok, thanks for clearing that up. And thanks for the warning! :D
     
  7. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    I'm still getting problems. If I use the propsToListInLobby String[], I get the same issues as when I use the Hashtable... i.e. the information goes missing
    So:
    - Can the hashtable be accessed from the lobby?
    - Why might the info that I'm putting into the string[] or the hashtable just vanish as it appears to?

    Thanks.
     
    Last edited: Jul 19, 2013
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Not sure where exactly this fails but I just tried with the Worker Demo from the PUN package.
    In there, in class MainMenu, modify the createGame call to:

    Code (csharp):
    1. PhotonNetwork.CreateRoom(this.roomName, true, true, 10,new Hashtable() {{"myProp", true}}, new string[] {"myProp"});
    In OnGUI() find the label which displays the room info and modify it to:

    Code (csharp):
    1. GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers + " " + roomInfo.customProperties.ToStringFull());
    This displays "{myProp=True}" after the room's name in the lobby.
    Basically you set properties as Hashtable (it's a set of key-values) and the string[] tells the server which props you need in the lobby to let your clients pick rooms by "content".
     
  9. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    Ahhh ok, I get it now. Thank you!