Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Photon Unity Networking

Discussion in 'Connected Games' started by tobiass, Aug 23, 2011.

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,098
    @DuvE: Sorry about the confusing doc and comparison. That's not our intention but things are a bit complicated to explain. Let me try.

    1: Games done in Bolt make the clients of a match connect to the host, which is also done in Unity / Bolt. All communication goes through this one instance, be it on a user's machine or on a server. If run on a server, we talk about hosting dedicated Bolt instances, which Exit Games does not provide. This doesn't define how authority is handled. It's only how clients connect.
    For PUN, there is no "host" instance. The clients connect to a server, which distributes their messages. It's also a star-topology but a "dedicated" server in the middle that always only enables players to communicate. The server for PUN is an "advanced relay", which means it can send some message to "all other" players in a room (and more).

    1.B: You pay for CCUs in Bolt because Bolt uses our servers for matchmaking and relay, if that's needed. Also, you fund production of Bolt with a somewhat fair share, based on your success. It's not a upfront fee that may never pay out.

    1.C: Bolt Dedicated Server cannot be hosted on Photon Cloud because that particular cloud is built to run Photon Servers, not arbitrary software.

    2: Hosted on clients side is fine for many games and it's affordable. A lot of games use this model, although you're right: The dedicated server is the optimum. It depends on your ambitions and funding, if a dedicated hosting is feasible. You can host the heck out of Bolt instances at will.

    3: PUN is less good for shooters, because the integrated features are different from Bolt. It's a different solution with different features and targets. Bolt was developed with action games / shooters in mind, PUN not.
     
  2. DuvE

    DuvE

    Joined:
    May 22, 2016
    Posts:
    74
    @tobiass:

    Thanks for a quick and detailed answer. But I need to ask some more questions to make this perfectly clear for me.

    4. In my previous post, I also asked about CCU and gave an example. Could you please check it too. Basically, I asked if there is 1000 player playing a game and only 50 of them used some special item to enable "Searching for a Duel" state. Other 950 player playing offline (until they decided to activate this item in the game), so the CCU will be only 50?

    5. About Photon Bolt Host Migration (for 4-5 players room for example), are there tools to implement this in Bolt? Or I need to write this migration system myself?

    6. If I decided to make a game using Bolt with one Player-as-Server variant, will it be possible (I mean not extremely hard) to convert this to a Dedicated server system? Or I need to rewrite all Bolt code in my game?

    7. And last and most silly question of all. I can't find some basic info about differences of the relay server and actual Dedicated or Client server/host? I need to understand which operations happen on Host Server and wich on the relay server? Relay server creates rooms and connects players to each other, but all the objects syncs happen on the actual Host server, right?
     
  3. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    317
    Hi,

    Ok, I could reproduce, you are talking about the roomInfos not being updated right? In my tests I do get the callbacks but the roominfos is not updated. it will be fixed in the next update.

    if it's a different issue, can you explain?

    Bye.

    Jean
     
  4. onurerler

    onurerler

    Joined:
    Apr 10, 2013
    Posts:
    5
    Hi,
    I mean if i set custom properties of currentRoom, CustomProperties hashtable stay empty

    I modified SetCustomProperties method in the room.cs file temporarily to work in offline mode

    my modified method is:

    public virtual void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedProperties = null, WebFlags webFlags = null)
    {
    Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable;

    if (this.isOffline)
    {
    // invoking callbacks
    this.LoadBalancingClient.InRoomCallbackTargets.OnRoomPropertiesUpdate(propertiesToSet);
    this.CustomProperties.Merge(customProps);
    this.CustomProperties.StripKeysWithNullValues();
    }
    else
    {
    // merge (and delete null-values), unless we use CAS (expected props)
    if (expectedProperties == null || expectedProperties.Count == 0)
    {
    this.CustomProperties.Merge(customProps);
    this.CustomProperties.StripKeysWithNullValues();
    }

    // send (sync) these new values if in online room
    this.LoadBalancingClient.LoadBalancingPeer.OpSetPropertiesOfRoom(customProps, expectedProperties, webFlags);
    }
    }
     
  5. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    317
    Hi,

    yes, that's what we have now in our code base and will be shipped in the next update.

    Bye,

    Jean
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,590
    Where/how do I limit the number of players that will be placed in a room by JoinRandomRoom?

    And if I don't set it, what limit applies by default?
     
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,041
    You use the RoomOptions when you create the room.

    Code (CSharp):
    1.      
    2.         var ro = new RoomOptions();
    3.         ro.MaxPlayers = 24;
    4.         PhotonNetwork.JoinOrCreateRoom("RoomName", ro, null);
    5.         // Could also use PhotonNetwork.CreateRoom("RoomName", ro, null);
    6.         //if you don't want to try joining an existing room first
    7.  
    From memory I think the default is 8, but I could be wrong, I always specifically set the amount.
     
    JoeStrout likes this.
  8. BrandonF_doghead

    BrandonF_doghead

    Joined:
    Apr 17, 2018
    Posts:
    5
    Hello!

    My team is using PUN 2 and Photon Voice 2 in a project of ours. We are currently having issues with v2.6 for both PUN and PUN Voice 2.

    Here is a reference to both assets on the Unity Asset Store, just to make sure we are referencing the same ones:
    PUN 2- https://assetstore.unity.com/packages/tools/network/pun-2-free-119922
    Photon Voice 2 - https://assetstore.unity.com/packages/tools/audio/photon-voice-2-130518

    We are having an inconsistent bug occurring when users are the same room. Even though the Photon.Voice.Unity.Recorder is created properly and receiving local input (verified using the Debug echo), the other users cannot hear each other. This issue does not always occur and is somewhat random. In testing this, the issue occurs about 20-30% of the time.

    When this issue occurs, we have traced the stack and found Photon.Voice.VoiceClient's delegate RemoteVoiceInfoDelegate OnRemoteVoiceInfoAction is not being invoked. When this delegate is invoked, the issue does not occur and the users can hear each other.

    I'm posting this in hopes someone can guide us in the right direction if there is in fact something we are doing incorrectly when initializing the Photon voice components. Does anyone have an idea what we may be doing wrong?

    Thank you!
     
  9. nikix22

    nikix22

    Joined:
    Jan 16, 2015
    Posts:
    19
    Hi to all :) I have one issue with using Youtube player inside application and PhotonNetworking together.
    I am getting after some short time DisconnectByClientTimeout and player LeaveRoom and it disconnects in the middle of the game, while there is no Youtube player all works perfect.
    So far I founded that cause can be that something is activating OnApplicationPause method and that causes PhotonNetworking to do disconnects without reason because it thinks that is minimized mobile application? I am running on PC so I don't need that :).
    This is only happening when I am using Youtube player plugin in the level and run multiplayer.

    So I am wondering how I can prevent PhotonNetworking to not receive DisconnectByClientTimeout event? I need only when user press some key.
     
  10. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,041
  11. nikix22

    nikix22

    Joined:
    Jan 16, 2015
    Posts:
    19
    Yes, it is enabled, and even photon itself is setting it to enabled, from code. It is just confusing that photon is receiving event to disconnect withou players explicit command, can't find the cause.
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,098
    Does Unity call OnApplicationPause, when you run the Youtube player?
    Check if Update() is being called by Unity, while you play videos. If not, the PUN client will stay connected for a while but ultimately timeout to prevent users from being connected indefinitely.
     
  13. JohnTube

    JohnTube

    Joined:
    Sep 29, 2014
    Posts:
    48
    Hi @BrandonF_doghead,

    I replied on our forum here.
    Let's continue the discussion there.
     
    BrandonF_doghead likes this.
  14. nikix22

    nikix22

    Joined:
    Jan 16, 2015
    Posts:
    19
    Hi :) there is a method inside YoutubePlayer class - OnApplicationPause. That could be a cause. I think I tried before to disable it somehow, but it looks like it is called again etc.
    Update is called in many places, I don't think that is a issue.
    ... Also, I will try next situation. Maybe this is happening if there is just one player in room? Sounds logical that this can be cause disconnecting because there is no need to transfer anything through network?
    Will try with more players in meantime...
    Thanks for fast reply! :)
     
    Last edited: Feb 11, 2019
  15. nikix22

    nikix22

    Joined:
    Jan 16, 2015
    Posts:
    19
    I tried on other computer, older one :) all is perfect!!! It looks like there is problem on my local machine.
     
    tobiass likes this.
  16. DavidSWu

    DavidSWu

    Joined:
    Jun 20, 2016
    Posts:
    54
    We do mobile, but whenever we want to play something external, like an ad, we set PhotonHandler.Instance.KeepAliveInBackground to 5*60*1000 (5 min)
     
    nikix22 and tobiass like this.
  17. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,098
    We just released a minor update to PUN 2 and PUN Classic.

    v2.7 (13. February 2019) (download)

    Fixed: Offline mode. Custom properties are now set properly.
    Renamed: PhotonNetwork.BackgroundTimeout is now PhotonNetwork.KeepAliveInBackground.
    Fixed: PhotonNetwork.KeepAliveInBackground now sets the ConnectionHandler.KeepAliveInBackground, which actually affects the background keep-alive.
    Fixed: A crash problem on Nintendo Switch. Setting a Thread.Name caused a crash in some Unity exports. We work around this by simply not naming internal threads.
    Updated: Photon3Unity3d.dll library to 4.1.2.9, rev4985.
    Photon Chat:
    Added: Client API for Max Subscribers and Publish Subscribers features inside public channels.

    v1.93 (17. January 2019) (download)
    Fixed: Support for 2018.3 and newer prefab editing workflow.
    Fixed: SetInterestGroup() for Offline mode. If offline, it can simply skip the call to OpChangeGroups and avoid some log spamming.
    Fixed: RPG Movement Demo. It was all-black in the last version, it seems.
    Updated: To Photon3Unity3d.dll v4.1.2.6, which is the same as used in PUN 2 with several performance improvements. See plugins\release_history.txt.
    Added: PhotonPing classes for the Best Region feature. They are not part of the used dll anymore (see below).
    Updated: SocketWebTcp.cs to match the new photon dll. It's now only compatible with Unity 5.3 and up.
    Photon Chat:
    Added: Client API for Max Subscribers and Publish Subscribers features inside public channels.
     
  18. Vagrod

    Vagrod

    Joined:
    Aug 4, 2017
    Posts:
    61
    (see UPD first)

    Hi! I just started using PUN2, and I cannot figure out where I am wrong:
    I am doing this:

    1. From LoadBalancingClient:
    Code (CSharp):
    1. AppId = PhotonAppId;
    2. AppVersion = Application.version;
    3. ConnectToRegionMaster(region);
    4.  
    5. PhotonNetwork.LocalPlayer.NickName = $"Player-{Guid.NewGuid()}";
    6. PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = Application.version;
    7. PhotonNetwork.ConnectUsingSettings();
    8. PhotonNetwork.GameVersion = Application.version;
    on every Update
    Code (CSharp):
    1. Service();
    From MonoBehaviourPunCallbacks:

    2. On OnConnectedToMaster:
    Code (CSharp):
    1. if (!PhotonNetwork.InLobby)
    2. {
    3.     PhotonNetwork.JoinLobby(MultiplayerClient.Instance.Lobby);
    4. }
    where MultiplayerClient.Instance.Lobby is
    Code (CSharp):
    1. private TypedLobby _lobby;
    2.  
    3. public TypedLobby Lobby => _lobby ?? (_lobby = new TypedLobby("swo default", LobbyType.Default));
    3. On OnRoomListUpdate I have simple "write every item to console"
    4. When player clicks New Room:
    Code (CSharp):
    1. var options = new RoomOptions();
    2. var rules = new Hashtable();
    3.  
    4. rules["dummy"] = "1";
    5.  
    6. options.CustomRoomPropertiesForLobby = new[] {"dummy"};
    7. options.CustomRoomProperties = rules;
    8. options.MaxPlayers = 2;
    9. options.IsVisible = true;
    10. options.IsOpen = true;
    11.  
    12. var player= new Hashtable
    13. {
    14. };
    15.  
    16. var success = PhotonNetwork.CreateRoom(Guid.NewGuid().ToString().Substring(0, 5), options, MultiplayerClient.Instance.Lobby);
    17.  
    18. if (success)
    19. {
    20.     Debug.Log("Room created");
    21. }
    5. When on one device I am creating new room, I see my debug "Room created" message (so everything is fine), and OnJoinedRoom is called right after. But when I launch second game instance, on other device, OnRoomListUpdate is always called with empty list. It returns empty list of rooms no matter what. I'm not seeing room I just created on other device.
    Where is my mistake?

    And how to re-request rooms? OnRoomListUpdate is called only when PhotonNetwork.JoinLobby is happened, so now on my Refresh Rooms button I am leaving lobby, and re-entering same lobby to make OnRoomListUpdate to trigger again.


    UPD: On the next day, on another network, at work, all worked. I'll check later at home -- why is it not working on a home wifi.
     
    Last edited: Feb 18, 2019 at 8:37 AM