Search Unity

Third Party Photon Unity Networking

Discussion in 'Multiplayer' started by tobiass, Aug 23, 2011.

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @ddalacu: You posted in our forum as well. There, Christian answered.

    @Sachinv2: I am looking into this. If there's a simple fix, I'll let you know.
     
    ddalacu likes this.
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @Sachinv2: You can get Chat to run with WebGL somewhat easily.

    Replace ChatPeer.ConfigUnitySockets() with the complete method from the LoadBalancingPeer and then remove the part that sets the PingImplementation. This is not available in the Chat API, so it can't be set.

    The SocketWebTcp now sets the SerializationProtocol = "GpBinaryV18", which means you have to set the serialization protocol also in Chat (to match this). In the ChatClient constructor, in a line below the chatPeer creation, set:
    this.chatPeer.SerializationProtocolType = SerializationProtocol.GpBinaryV18;

    This should allow you to connect and chat.
     
    Last edited: Oct 18, 2018
  3. Graphicalgeek

    Graphicalgeek

    Joined:
    May 14, 2009
    Posts:
    218
    Hey @tobiass, can we expect an updated Memory Game Demo for PUN2 anytime soon?
     
  4. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    @tobiass When I change scenes while photon chat is connected and running.
    I run
    Code (csharp):
    1. chatClient.Disconnect();
    and then change scene and it still trying to access my Chat script
    do I have to wait a few frames or something before I change scene?

    Also do I have to have Pun installed in order to use Photon Chat?
    Notice to get the photon chat AppID for the connect it uses a PhotonNetwork method.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @Graphicalgeek: At the moment, this is not planned. Are you using it as a sample for turnbased games? With or without persistency? Just to understand the core of the question...

    @Shadowing: You don't have to disconnect the chatClient because you do something in PUN or are loading scenes. I think Chat may still be lacking the ability to keep the connection if you load but overall, it's independent from the scenes.

    If you disconnect and reconnect, you'd have to wait until the disconnect is confirmed. There is a status change for that.

    You can use Chat fully independent from PUN but the Chat API in the PUN package may (accidentally) reference some part of PUN (PhotonServerSettings), so you may have to clean up a few files from Chat.
    You can definitely get rid of the reference to the settings and just apply a Chat AppId.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    We just released PUN v2.4 in the Asset Store with fixes and improvements. It's not causing a lot of breaking changes, so everyone should update in best case.

    v2.4 (24th October 2018)
    Fixed: Duplicated Instantiation Events when using PhotonNetwork.ReconnectAndRejoin: when a client rejoins a room, his server-side cached Instantiation Events get duplicated, resulting in duplicated objects. This has been fixed.
    Changed: When Unity exports with Runtime 4.x and Mono, PUN and Chat now use a new, async socket class to work around issues with Socket.Receive blocking indefinitely (and timing out). This is now available for UDP and TCP. IL2CPP is not using this.
    Note: We changed the "productname" internally from PhotonUnityNetworking to PUN2, to avoid a problem when building UWP apps with the AssemblyDefinitions in place. In that case, two .dbg files were created and put into the generated solution. This does not affect projects which import PUN (without the ProjectSettings file) but you should keep this in mind.
    Updated: The Photon3Unity3d.dll to v4.1.2.4 with some fixes and improvements:
    *** Version 4.1.2.4 (23. October 2018 - rev4868)
    Fixed: Fragment bug introduced in 4557 (12. March 2018). This kept one command per reassembled message in the incoming queue (without payload), which is a memory leak.
    Added: An upper limit for the calculated lastRoundtripTime (per ack) to prevent uncontrolled rtt changes due to garbled incoming messages. Protecting the rtt timer improves resending commands if needed. INFO level logging starts with: "LastRoundtripTime is suspicious".
    Added: SocketTcpAsync class, which is receiving with BeginReceive and EndReceive in callback. This should work for Unity's 4.x Runtime, which has a bug that blocks Socket.Receive() indefinitely.
    Changed: TPeer.ReceiveIncomingCommands() will now use dataLength as indicator how much was received.
    Internal: CalculateCrc() now uses a cached lookup table, which gives it much better performance (most obviously for longer datagrams). It's viable to turn this on by default.
     
  7. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Thanks man. I figured out my change scene issue. had nothing to do with chat disconnecting like I thought.
     
    tobiass likes this.
  8. Graphicalgeek

    Graphicalgeek

    Joined:
    May 14, 2009
    Posts:
    218
    Yes, without persistency.
     
  9. Ulises_P

    Ulises_P

    Joined:
    Feb 4, 2018
    Posts:
    15
    I'm looking for help, I have a script that has implemented the event OnTriggerEnter, whe a second player connects to the same Room the event is triggered all the time even if the Game Objects are not close to each other. I don't know why or what triggers the OnTriggerEnter
     
  10. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    So, how does photon 2 handle physics simulation? Anything new in this area?.. How does this whole thing compare to what Unity announced with their partnership with google.

    Is it possible to do a Battlefield like game with PUN 2?
     
  11. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    you can do that already in PUN classic, I would handle physics client side, and I would say anyone sane would do so. :D
     
  12. nikunjk21

    nikunjk21

    Joined:
    Jan 12, 2014
    Posts:
    26
    Hi,

    We're planning to make game like battle royal, where 100 player can play with each other on one large map.
    Also players can speak/chat among their team mates.

    I want to have all type of physics, position and other calculation on server, not client side. We need to have authoritative server which validates the player's actions.

    For a start, our plan is to include only 16 players and 84 will be AI bots. as we proceed further in development we may plan to add more players.

    I'm new to photon and can't able to decide which package perfect fit for our requirements. (PUN, Bolt, Realtime, Quantum, Self hosted server)
    And also let me know free version of PUN2 will work on such a scenario.
     
  13. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    @Kurtav published an asset on teh store in order to be able to sync many many bots. You may whant to check it out. Can´t remember assets name may be he can show up and post a link. If you whant to do server side, unless photon2 changes thi, in classic you will have to setup your own server infrastructure I believe.
     
  14. YPGames

    YPGames

    Joined:
    Mar 14, 2015
    Posts:
    7
    "PUN2 v2.4 " "Unity2018.2.14"
    Even if I connect from Unity Editor with execution and executable file, I can not suddenly enter the same room.
    Each room is not found and it always creates a room.
    I also tried "Basic Tutorial" but I can not enter the same room as well.
    I made it only to the Photon folder, but the situation does not change
    In the case of executable files, you can stay in the same room.
     
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @Graphicalgeek: Well, the PUN Classic sample for turnbased games also applies to PUN v2 mostly. I understand this is less practical than an updated sample but right now, we can't port the sample, so it's best to learn from that and apply the ideas to PUN v2. We will work on this when we can.

    This is normally driven by the physics, so I can only guess. Maybe the "remotely controlled" objects are set to some position but the physics engine doesn't agree and sets it somewhere else? You could Debug.Log() and check the callstack maybe. Also check if the objects are really networked.

    Synchronizing 100 players is not simple. It can be done with Photon Realtime and the server SDK but we don't have a "out of the box" solution and PUN is not even built with Battle Royale in mind.
    You could get PUN 2 but use the Realtime API for in-game communication (RaiseEvent) and use the server to optimize the updates that each players gets.

    @YamiuchiProject: Make sure you don't run both clients at the very same time. Creating and listing a new room takes a moment and if both clients attempt a JoinRandom at the same time, both may fail. We match players into rooms, which may fail especially when testing but it's not a "real life" problem as users rarely do this at the very same time (or if so, then some others will soon join both new rooms).
     
  16. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I have a question about the proper use of PlayerProperties.

    I'm currently using the PlayerProperties synced hashtables with very frequent updates (I think 5 times/second) to synchronize the state of each player in a room, including their transform and what they're doing with their hands. It seems to be working fine, but we've never tested with more than a few players.

    But a colleague just suggested that PlayerProperties might be synced not just within the room, but across all players on the server (for use in a lobby, for example). Thus my use of them here might be an abuse that will cause a lot more network traffic than using, say, Object Synchronization.

    The main reason I'm using custom properties here is that the prefab that represents a remote player is very different from the GameObject that represents the local player. That seems hard to accommodate with Object Synchronization. I guess if custom properties are not OK to use this way, I'll have to make do with RPCs. Or is there a better way?
     
  17. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No feedback on this (@tobiass)? Or am I posting in the wrong thread?
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @JoeStrout: You're in the right thread but the weekend happened first ;)

    While you could use custom properties to sync everything, they are not built for something else and are less flexible.
    Properties are always sent reliable and you have to put everything in a hashtable with string keys.

    Custom Properties may end up being sent to the Master Server for matchmaking but you have to explicitly define the string keys that are needed for matchmaking. See: CreateRoom, RoomOptions.CustomRoomPropertiesForLobby.


    For "live" data, which changes all the time (positions, etc), you should either use the PhotonView "observe" options with custom scripts or you can implement your own system for this with RaiseEvent.
    https://doc.photonengine.com/en-us/pun/current/gameplay/synchronization-and-state

    RPCs are also possible but again, these are always reliable. As long as the updates happen "all the time", you'd want to send unreliable.
     
    JoeStrout likes this.
  19. YPGames

    YPGames

    Joined:
    Mar 14, 2015
    Posts:
    7
    solved.
    When Fixed Region is left blank, different Region was selected.
    Editor was jp (so close to Japan), Exe was rue.
     
    tobiass and JoeStrout like this.
  20. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
  21. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Right, some updates fall in the middle. If those are related to something that's updated frequently, you can "inline" the extra values.
    An optimization is to send health within the frequent updates but on demand, when it changed.
     
  22. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    Would that be done using the "Unreliable on change" option?
     
  23. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    Hello, i'm trying to have a round timer for the room.. but i'm not finding information on how to do it.. on one of your old answers you suggested to look up InRoomRoundTimer.cs script but i can't find it in folders
     
  24. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    It can be done that way but it's simpler if your code for OnPhotonSerializeView (the observed component) will either send health or skip it.
    If the PhotonView is simply unreliable you probably want to send it along every time though.

    The InRoomRoundTimer is no more. Check out the PunTurnManager and IPunTurnManagerCallbacks. It includes a timer.
     
  25. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    Alright thanks

    for anyone wanting the same

    Code (CSharp):
    1.         float roundTime = ((float)(PhotonNetwork.ServerTimestamp - RoundStartTime())) / 1000.0f;
    2.         timerText.text = (roundTime / 60).ToString("00") + ":" + (roundTime % 60).ToString("00").ToString();
    where RoundStartTime is the PhotonNetwork.ServerTimestamp at the start
     
    tobiass likes this.
  26. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    For Pun2 I have to change all PhotonNetwork.(whatever) in pun1 to Photon.Pun.PhotonNetwork.(whatever) .. is that right or am doing it wrong ?
     
  27. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
  28. Nightology

    Nightology

    Joined:
    Jan 27, 2014
    Posts:
    71
    I like Photon pun 2, but I have a problem with the list room, I watched the asteroid demo.

    Everything is happening on the same stage.
    When a player creates a room, it adds a gameObject in the "ScrollView" of the "ListRoom" panel that has a "join" button for other players. This is ok.

    In the room, when the number of players reaches its maximum, the players must say that they are "ready" before the end of time, if they do not, then the function "PhotonNetwork.LeaveRoom ()" s' Execute for all players in the room and return to the "ListRoom" panel.

    And there is my problem, the gameObject in the "ScrollView" panel "ListRoom" does not want to destroy with the function "ClearRoomListView ()", as in the demo asteroid. He says that there are always 01 players in the room when it is empty, hence the fact that it is not destroyed. How can I destroy this room ??

    Can you help me?
     
    Last edited: Nov 12, 2018
  29. ChristianSimon

    ChristianSimon

    Joined:
    Jun 20, 2016
    Posts:
    8
    Hi @Nightology,

    the problem is, that the OnLeftLobby callback doesn't get called and so the RoomListEntries won't get removed correctly. I'm asking you to take a look at this topic from our forum. In this topic I provided two possible workarounds for this problem.
     
  30. Niels40

    Niels40

    Joined:
    Nov 6, 2017
    Posts:
    20
    Hi, i was wondering. If i use photon engine is it possible to use my own server instead of photons cloud?
     
  31. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
  32. Niels40

    Niels40

    Joined:
    Nov 6, 2017
    Posts:
    20
    would i be able to use PUN and let my users host there own dedicated servers?
    And how would the fees for such a thing work?
     
  33. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
  34. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    No, you don't, just add
    using Photon.Pun; 
    to the top of your script.
     
  35. AlteredPlanets

    AlteredPlanets

    Joined:
    Aug 12, 2013
    Posts:
    455
    HI, I am syncing blend trees in the animator over the server, but some floats and bools sometimes dont sync.

    animator photon view and tried photon serialize
    unity 2017 , latest PUN classic

    help please
     
  36. w_adams

    w_adams

    Joined:
    Apr 7, 2016
    Posts:
    34
    Hi, I'm trying to migrate from pun 1 to 2. In 1, we had PhotonServerSettings.HostType, but that seems to be gone now. How do I set my hosting type now?

    Thank you.
     
  37. Bertlapp

    Bertlapp

    Joined:
    Sep 7, 2015
    Posts:
    44
    Does a turn based tutorial for Pun 2 exists? Similar to the rock, paper, scissors example in Pun 1.
    Or can I find a turn based Class setup working with Pun 2 somewhere?

    Not 100% sure how to start turn based in Pun 2 for Photon.
     
  38. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @AlteredPlanet: I fear your description is too vague to help in detail. When you use OnPhotonSerializeView, you got it in your hands to make sure needed values arrive. If you send unreliable (selected in the PhotonView on the GO or Prefab), some updates may drop, yes.

    @w_adams: The new PhotonServerSettings are explained here.
    If the doc doesn't help, let us know what you want to setup and we will help.

    @BertVanEeckhout: At the moment, we don't have an updated turn based sample, sorry. The Rock Paper Scissors is still valid and you could look at that, then decide if you want to apply your knowledge to PUN v2 or stay with Classic (for however long).
     
  39. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    We just submitted an update for PUN 2 to the Store. We (e.g.) updated the compatibility with the new Prefab System of 2018.3, fixed bugs and reintroduced the PUN Classic PhotonTransformView.

    v2.5 (20th November 2018)
    Fixed: The RoomOption CleanupCacheOnLeave
    is now correctly set per room (if set for creation of the room). This bug caused a server-side cleanup of Instantiate-events, buffered RPCs and other buffered events, despite a different setting in the options. This messed with a game's state, if you wanted to keep networked objects when players leave.
    Fixed: Regression during PhotoView cleanup leading to loss of viewId in OnDisable and OnDestroy calls. Now OnDisable and OnDestroy can access the viewID. Pooling the game object will set the new viewID before OnEnable is called.
    Fixed: Asteroids Demo. The cached room list now gets cleared correctly when the client joins a room / leaves the lobby.
    Added: The component "PhotonTransformViewClassic", which provides all the options (and implementation) from PUN Classic (1.xy). Use this if you want to use the options that were previously available. This component is deliberately not used by default.
    Changed: The inspector for PhotonTransformView to hint about the PhotonTransformViewClassic and using your own synchronization in general.
    Changed: PUN now suppresses the compiler warning "649" on newer versions of Unity for some of our Basics Tutorial scripts. This helps us keep the used code simple and better at "teaching" PUN.
    Changed: The Realtime API no longer sends the actor properties on a rejoin. The values are known to the server and should not be updated. Set new values after rejoining the room, if that's needed.
    Fixed: Support for 2018.3 and newer prefab workflow to not show/deal the viewId field when editing a prefab.
    Fixed: ViewID assignment algorithm when reaching the max view ID value.
    Fixed: Removed harmless "duplicate"-warnig inside the DemoHub context. Now eventSystem is only created if needed.
     
  40. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    188
    From Photon docs, "PhotonTargets has some values ending on Buffered. The server will remember those RPCs and when a new player joins, it gets the RPC, even though it happened earlier. Use this with care, as the a long buffer causes longer join times."

    If you call the same buffered RPC over and over does it overwrite the last RPC or does it add to a list of prior RPCs that the new player cycles through? For instance, if I call an RPC that switches weapons 100 times, is it going to remember all 100 calls or just the last one?
     
  41. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
  42. Nikolasio

    Nikolasio

    Joined:
    Dec 6, 2014
    Posts:
    59
    Hi,

    In my setup there're two players in the room (only two allowed). When one player quits the room, the current room is closed so that nobody accidentally joins:
    Code (CSharp):
    1. PhotonNetwork.room.IsOpen = false;
    And at the same time this is a trigger for throwing the second player out of the room:
    Code (CSharp):
    1. if(!PhotonNetwork.room.IsOpen)
    2.      OtherPlayerLeft ();
    3.  
    4. void OtherPlayerLeft()
    5. {
    6.       PhotonNetwork.Disconnect();
    7. }
    When debugging, on the first device, room.IsOpen is false indeed when the first player quits, but on the other device the condition is never met, so room.IsOpen stays true and OtherPlayerLeft() is never called.

    I'm using this in a turnbased setup with a refactored PunTurnManager.
    What could be the issue?


    EDIT: Solved! Before PhotonNetwork.room.IsOpen = false got called, the player was already disconnected!
     
    Last edited: Nov 30, 2018
  43. jeffersoncosta

    jeffersoncosta

    Joined:
    Aug 11, 2018
    Posts:
    4
    Hello! Is there anyway to use others namespaces on the PhotonNetwork.cs ? I want to make an custom method inside it but it's not possible since i upgrade to the 2.0 version. Its not possible find the others namespaces
     
  44. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    Hi, when searching for a random room, can i specify only join a random room IF it doesn't contain a certain custompropertiy? thing is a store a room password in customroomproperties, and i don't want joinrandomroom to enter a room with a password


    EDIT:

    Ok i did my own little method ... i don't know if this will break things in the background but it's what i can do for now

    Code (CSharp):
    1. void FindRandomGame()
    2. {
    3.         RoomInfo[] rooms = PhotonNetwork.GetRoomList();
    4.  
    5.         for (int i = 0; i < rooms.Length; i++)
    6.         {
    7.             if (!rooms[i].CustomProperties.ContainsKey(RoomCustomProperties.Password)){
    8.  
    9.                 if (rooms[i].PlayerCount < rooms[i].MaxPlayers)
    10.                 {
    11.  
    12.                     PhotonNetwork.JoinRoom(rooms[i].Name);
    13.                     return;
    14.                 }
    15.             }
    16.         }
    17. }
     
    Last edited: Nov 30, 2018
  45. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    is any player able to change other player's customproperties ? is there a method to restrict playercustomproperties to be only changed by masterclient ?
     
    Last edited: Dec 3, 2018
  46. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @jeffersoncosta: You just have to reference the other namespaces (using xyz), as usual.

    @Smart-hawk1: I see two simple alternatives: You can set your "pw" property to "none" (or even better to "") in all rooms without a password and turn this into a filter for JoinRandomRoom. Or you use two lobbies (both "Default" typed) but when a room has a password, you put them in the "private" lobby. This means you have to know on creation time, if the room gets a password or not.
    For both, the benefit is that you don't have to fetch the list first, then select a room. This is something that regularly causes problems on games as they grow in popularity.

    @ShinigamiUzi: Technically, there is no restriction and there is none we could turn on. You would need a plugin to restrict this.
     
  47. vsnry

    vsnry

    Joined:
    May 4, 2018
    Posts:
    35
    I also posted this on the Photon forums, but they don't seem very active.

    I'm new to making multiplayer games and currently looking for an easy and simple multiplayer solution. I looked at UNet and it worked perfectly and was very simple, but it's getting discontinued soon and I heard it's not that good anyway, plus expensive. So now I'm stuck with choosing between PUN and Bolt. I've downloaded Bolt and tried to convert my singleplayer first person character controller by following the written tutorials, but it was so confusing and hard that I got lost, also couldn't find many online resources on it. PUN on the other hand looks pretty similar to UNet and has a lot of resources, but I don't really know which one to use.

    My game is a simple survival game, I'm only planning to have about 4 players per server, all on the same team fighting off a bunch of NPC waves. Would you recommend using PUN or Bolt for this? I feel like the Bolt peer to peer like system would work much better, but it's also very hard for me to learn how to code games with it.
     
  48. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Hey, is it possible to let players create their own servers (and hosting those servers by themselves)?
     
  49. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @vsnry: I would say you don't get a lot of input on your question, because it's hard to answer and to a good degree it's subjective. Both solutions enable games you describe but it's unclear if you could achieve your goal with either.
    If you have a better feeling about Bolt, give it another try. Invest some time into learning it. It's a really good package with lots of useful features, especially for shooter / first person style of games. This might be worth the extra time to learn it.

    @arturnik17: At the moment, we don't provide a redistributable server package, so: No.
    What are you building?
     
  50. vsnry

    vsnry

    Joined:
    May 4, 2018
    Posts:
    35
    What about Photon PUN and Photon Server? If I have Photon PUN and don't want to use Photon Cloud, then would the prices of both PUN and Server stack? So, if I'm using PUN and want 500 connections with Photon Server would I also have to get the 500 CCU PUN bundle, or would paying for the server be enough?