Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon Unity Networking

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

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    PUN Classic is PUN 1.x and not recommended anymore.
    PUN 2 fixed a lot of the problems and is still something you can use, yes.
    However, there are not a lot of reasons, why you shouldn't use Fusion. It supports newer features of Unity, has proper authority (which clarifies who does what) and the synchronization of objects is better out of the box. Not everything you do with it has to be high-end.
    Having advanced features doesn't mean you have to use them. But later on, you could.
    Coming from PUN, use the shared mode and you don't have to worry about how the host runs everyone's state via input alone.
     
    Last edited: Sep 26, 2022
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    I was now able to check in Unity 2019.4. and could build and run UWP after one simple fix:
    In NetworkingPeer.cs, line 839, change the compile condition from UNITY_WINRT to NETFX_CORE (keep the not in editor condition).
    That works, pings the regions (when using Best Region setting) and seems fine overall.
    I actually can't even make sure this works in 2017.x too.
     
  3. ayrton2389

    ayrton2389

    Joined:
    Oct 25, 2013
    Posts:
    26
    Thank you for the solution! i really appreciate it!
     
    tobiass likes this.
  4. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hello, I think that there's a BUG in Photon PUN.

    I have a Gameobject that can be moved by 2 users, and basically each of them take its ownership pressing a button. Unfortunately, after some movements (just position and rotation), when one of them take its ownership it "jitter" quite a lot (it move to another position and back to the right one) on the user that "lost" the ownership (but not on the user that is the new owner).

    This issue does not happen just in my game, but in the every PUN tutorial too.

    It's easy to reproduce:

    1 - create a Cube, with its PhotonView and PhotonTransformView
    2 - create a simple script, attached to the cube, with the function "pv.RequestOwnership();" and a button that call this function
    3 - in gameplay, user1 can move and rotate the cube with the mouse in the scene, and its position/rotation are updated on user2
    4 - user2 press the button to take the ownership, and to move and rotate the cube, and its position/rotation are updated on user1
    5 - after a couple of movements, and changing from user1 and user2, you will see that the cube, on the user that just lost the ownership, will move around its position a bit

    Is it a (huge) bug?

    Many thanks!
     
  5. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    You should post your code that reproduces the bug, otherwise it isn't certain whether it's Photon or your code that's at fault.
     
  6. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    It's not a matter of my code. As I wrote, it does happen in every single Photon PUN project that I've made from scratch, or downloaded from Github.
    If you just create a very simple scene, as I described above, you will see this.

    Anyway the code is very simple:
    Code (CSharp):
    1. public PhotonView pv;
    2.  
    3. public void TakeOwnership()
    4.     {
    5.         pv.TransferOwnership(PhotonNetwork.LocalPlayer);
    6.     }
    The good news is that I've been able to avoid this issue, with some lines of code (but in my opinion this behaviour is quite a shame)

    This is my solution:
    Code (CSharp):
    1. public PhotonView pv;
    2. public bool imMovingTheGameobject;
    3. List<PhotonTransformView> ptvList = new List<PhotonTransformView>();
    4.  
    5. void Start()
    6.     {
    7.         foreach (var observed in pv.ObservedComponents)
    8.         {
    9.             if (observed.gameObject.GetComponent<PhotonTransformView>() != null)
    10.             {
    11.                 PhotonTransformView phv = observed.gameObject.GetComponent<PhotonTransformView>();
    12.                 ptvList.Add(phv);
    13.             }
    14.         }
    15.     }
    16.  
    17. void Update()
    18.     {
    19.         if (!pv.IsMine)
    20.         {
    21.            SetTransformViewEnabled(true);
    22.         }
    23.  
    24.         else
    25.         {
    26.            SetTransformViewEnabled(imMovingTheGameobject ? true : false)
    27.         }
    28.     }
    29.  
    30.  
    31. void SetTransformViewEnabled(bool value)
    32.     {
    33.         foreach (var ptv in ptvList)
    34.         {
    35.             if (ptv.enabled != value)
    36.                 ptv.enabled = value;
    37.         }
    38.     }
    39.  
    It's not so nice, because I'm enabling and disabling the TransformView Component on Update, but it work, and actually it seem to me the best solution for this bug
     
    Last edited: Dec 1, 2022
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    You've posted your workaround code, but not how you've fully implemented the ownership transfer itself. For example, you haven't shown the RequestOwnership call or the code on the current owner that handles the OnOwnershipRequest callback.

    The only reason I ask for clarification is that I haven't encountered the same behaviour myself with ownership transfer.

    Edit: My understanding (which works as expected) is that TransferOwnership is called on the current owner, passing the id of the new(requesting) owner as an argument, when it receives a request to transfer ownership. But in your brief example you seem to be transferring ownership to the same client that invokes the transfer, which doesn't make sense.

    https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/ownership-transfer
     
    Last edited: Dec 2, 2022
  8. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    The "TakeOwnership" function in called by the user that has NOT the ownership, pressing a button "TAKE THE OWNERSHIP".
    The function
    Code (CSharp):
    1. TransferOwnership(PhotonNetwork.LocalPlayer)
    as far as I know is exactly the same as "RequestOwnership"
    I dont have any callbacks, because I don't need them, and I suppose that it should work just as it is
     
  9. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    I'm assuming your TakeOwnership method is executing on the client PC that is wanting to become the new owner, in which case I think your understanding of how it works is flawed...

    From the docs I linked to in my previous post, regarding the OnOwnershipRequest callback,
    When someone requests ownership, this will be called by PUN on the client that is the current owner. As you can see, the current owner calls view.TransferOwnership(requestingPlayer.ID) to actually transfer the PhotonView to it's new owner.


    TransferOwnership is definitely not the same as RequestOwnership, and as far as I understand it, what you have won't work as it is, which I think is borne out by the fact that you are noticing odd behaviour,

    I'm using the RequestOwnership/TransferOwnership program flow exactly as explained in the docs example and it works perfectly.

    Maybe @tobiass can weigh and correct me if I'm wrong.
     
    Last edited: Dec 4, 2022
  10. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Tank-you for the explanation.
    I've tried with "RequestOwnership" but the issue is still there
     
  11. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Sorry you're still having this problem, but it's going to be difficult to help further unless you post example code that reproduces the problem, which so far you haven't.
     
    Last edited: Dec 5, 2022
  12. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Your logic is not correct at all, lets say player 1 is the owner, as of now, if player 2 presses the button it can't take ownership from player 1, player 1 has to give it, you will have to send an RPC to the player who presses the button which is called by the owner (player 1)
     
  13. hellaeon

    hellaeon

    Joined:
    Jul 20, 2010
    Posts:
    90
    Hi there. I'm trying to find out where Photon.Realtime fits in all the old and new photon stuff.

    It seems to be the unspoken child.

    We like to use it because of the exposed interfaces allows us to come up with a dependency injection setup for our systems. @tobiass are you able to summarise in a couple of sentences where realtime sits and it's development sits? Will it be supported for a number of years yet?

    Cheers
     
  14. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    The Realtime API is the basis for pretty much all SDKs we offer. It solves the matchmaking, enables communication in rooms and acts as relay for Fusion (if needs be). It will be a central API for Photon in the next years and you can use it directly, for sure.
    It's a bit more basic to explain and we have higher level solutions on top of it, which means we don't talk about it as much, yes. Also it's not changing quickly, so there are less news about it, too.

    The latest version of the Realtime API is on our SDK download page.
     
  15. hellaeon

    hellaeon

    Joined:
    Jul 20, 2010
    Posts:
    90
    Thanks @tobiass we have started to implement it. Thanks for the information.
     
  16. GamePyro-com

    GamePyro-com

    Joined:
    Jul 28, 2018
    Posts:
    197
    Hello

    Have problem getting Photon PUN 2 to work in my project try since much hours different scripts i coded and configurations.

    I have a Player with (Rigidbody, Sphere Colilider, Player Controller Script, Spring Joint)

    The Photon View, Photon Transform View work at it when i instantiate the Player

    But the Player Model with animator is instantiated also after it with the Model player selected.

    So the Player Model is Child of the Player. It has the Animator, a Player Model Data Script on it

    So its the Player as Parent and in it the Player Model as Child

    also tryed with Instantiate with PhotonNetworking and at the Child PlayerModel his Own PhotonView.



    Always same problem.


    I tried set at the Player model also the Photon Transform View and Photon Animator View. and at the Parent it auto find all and it finds in child. But the animations from Child are not much synced to other players not all and only some also not the speed and pose .




    I wrote a script and changed the Photon Animator that it can be at the Parent and use the Animator from Child to sync over network but same problem only some animations get synced.
    It feels like Photon hangs at syncing and only sends some changes when it uses the Animator and sync from Child object.



    If i instantiate the Player with PhotonView with Photon Networking and the Player Model without set Player as Parent then it works it synces the Animations all and then in Editor i can move the PlayerModel with Mouse into the Player it works all but not when set Player as Parent with Script to the Child why.


    When sync only Player Model to other Players over network it is at 0,0,0 because it needs the Positions of the Player thats why its Parent in Player as Child. Also for other scripts work that when other player crash in so it need be Player with the Player Model as Child synced


    Hope someone can help find the problem or fix it or is it a Photon problem


    Also tryed same as he done its nearly same i do but same problem still not all animations get synced



    Regards Thank you so much
     
  17. Joginder_Pal

    Joginder_Pal

    Joined:
    Oct 10, 2022
    Posts:
    2
    i am stucked in same situation.. can you tell me what you done to fix this...
     
  18. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,635
    Ya there is a option somewhere on a manager that destroys objects when new players join or something like that. Can't remember fully.
     
  19. Joginder_Pal

    Joginder_Pal

    Joined:
    Oct 10, 2022
    Posts:
    2
    Can You tell me how can i fix this issue for my project. as i am also stuck here too
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    I posted some questions for that issue. Try to find the answers for them and then go from there.
    It is a usage issue mostly. If you are stuck, please post a new thread, tell us the related info for your project, etc. "I am stuck there too" is not enough info to help properly.
     
  21. unity_8C2CBBFCCF91C9EF8710

    unity_8C2CBBFCCF91C9EF8710

    Joined:
    Apr 26, 2023
    Posts:
    1
    201 means a player has loaded a plugin into their game
     
  22. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    374
    Hello. I'm desperate.

    In my game, I connect to photon, connect to lobby, create a room and enter it. Everything correct and with the correct logs.

    When I do it in "editor", the player stays without problems. As long as it takes, without errors.
    When I do it in "standalone build" (windows) the player quits the server after approximately 60 seconds.

    I have seen examples, tutorials, external code, videos on youtube and I GET NOTHING.

    Please help!!!

    Unity version 2021.3.27f
    Photon Pun 2.42

    MORE INFORMATION

    I have created a log. Both in "editor" mode and in "build" mode, the connection to photon and room occurs.

    When they enter the scene, the PHOTONVIEW data is this:

    1001 1 True #01 'Admin' ab117f6b-324b-42fa-ba08-d9b4868466fd 2023/15/06 22:33:50.311
    (IDVIEW, number, ismaster, nick, code and date)


    And this is the other player's log:

    2001 2 False #02 'Admineditor' adae47d4-eb97-4f4e-bd56-c78bb7cbf67f 2023/15/06 22:35:08.776

    It seems that both are perfectly identified, but they do not appear on the scene together. And, as I say, the one in "build" closes after 60 seconds (now longer because I've raised the keepalive value...)

    What I don't know either is if I'm going to get some kind of response, but not for not trying.

    MORE INFORMATION

    With double instance of UNITY EDITOR open, the cars fit perfectly into the level. They see each other, move and collide.

    The problem, in short, is confirmed in the "build" mode. In the "editor" mode it is confirmed that it is not a matter of problems with the players.
     
  23. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,635
    id ask for help on Discord.
    Also if you aren't fall along on your project I would use Fusion not photon. Photon is depreciated.
     
  24. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    374
    Thanks a lot!!!
    But I paid PHOTON PUN until the end of 2024 and I would like you to give me customer service.
     
  25. Lukeesta

    Lukeesta

    Joined:
    Jan 7, 2016
    Posts:
    77
    As a paying customer you can write us an email to developer@photonengine.com and we will support you with your issues. I'm personally not very familiar with PUN but with other of our libraries so I can't be of much help immediately here. If you write us an email the right person will get back to you.
     
  26. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    374
    Thanks!!!
     
  27. ELC2909

    ELC2909

    Joined:
    Jun 17, 2016
    Posts:
    8
    Excuse me, I want to ask for those who know/have used Photon before.
    Can Photon be deployed to a private dedicated server (without using a Photon server), like other networking solutions (ex: Mirror, Fishnet, NGO, et al)?
     
  28. Lukeesta

    Lukeesta

    Joined:
    Jan 7, 2016
    Posts:
    77
    Photon is a brand. There are many Photon products:
    - PUN > Does not have a server & Photon Cloud Only
    - Fusion > Has both dedicated server and cloud (shared) mode. In all modes a connection to the Photon Cloud is required. In server mode all real time game traffic goes from client > servers directly.
    - Quantum > Does not have a server & Photon Cloud Only
    - Realtime > Does not have a server & Photon Cloud Only (You can have a dedicated server connect to the cloud sim that acts as a client but this is a rare case)
    - Voice / Chat > Does not have a server & Photon Cloud Only
     
    ELC2909 and Petr777 like this.
  29. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    I just updated PUN 2 to v2.43 in the Asset Store.
    The main update are the new library and Realtime API version (v4.1.7.0) which wrap up a lot of changes for WebSockets.
    Aside from that, there are also a few fixed for issues in the included demos.

    v2.43 (21. August 2023)
    Updated: Library, Realtime and Chat API to 4.1.7.0. This includes many improvements for WebSockets and connection-loss debugging (specifically for UDP, SocketUdp class). More in the related change logs.
    Updated: To Unity 2019.4.
    Fixed: PUN Basics GameManager to not accidentally send the network Instantiate request before joining the room (which could happen if the scene was loading too fast). See comments in OnJoinedRoom().
    Fixed: PUN Basics GUI Button call of LeaveRoom by removing the return value from the called method. It failed with the error "Method arguments are incompatible". Adjusted related code (minimally).
    Changed: Procedural Demo now randomizes the initial "seed" value. "Nice to have" addition.
    Changed: Demo Hub to include Procedural Demo.
     
    Farsam likes this.
  30. ELC2909

    ELC2909

    Joined:
    Jun 17, 2016
    Posts:
    8
    I see.... Thanks for the information
     
  31. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    Just updated PUN 2 with the most recent Realtime and Chat APIs.
    This wraps up several smaller fixes (since v4.1.7.0) and should be an effortless update for everyone.

    v2.44 (14. December 2023)
    Updated: Library, Realtime and Chat API to 4.1.7.4. Fixes and changes for Best Region Selection and reporting client timeouts to server. More in the related change logs.
    Updated: PUN Wizard panel. Replaced forum link with pointer to join our Discord.
     
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    Last edited: Jan 29, 2024
    TokyoWarfareProject and yuliyF like this.
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    We just updated PUN 2 in the Asset Store to v2.45.
    This time, it includes an important fix for Random Matchmaking (when joining rooms with a specific Max Players value). Everyone with 2.44 should update. There are few other changes, so no effort involved.

    v2.45 (05. February 2024)

    Fixed: OpJoinRandomOrCreateRoom and OpJoinRandomRoom. The last version introduced an issue with random matchmaking, when using MaxPlayers as filter to find rooms. It caused clients never to find fitting rooms in those conditions.
    Updated: Library, Realtime and Chat API to 4.1.8.0.

    Important: Due to breaking changes, all clients with versions v4.1.7.2 to v4.1.4 must be updated to fix "JoinRandom" with MaxPlayers being not zero. Alternatively change GamePropertyKey.MaxPlayersInt to 243 if your project compiles the LoadBalancingApi.
    Changed: Random Matchmaking for low CCU test cases: When multiple clients join random rooms or create them at the same time, they will now match into the fitting rooms instead of missing one another. This is only done with a low room count / low CCUs for the virtual app. This avoids problematic cases when testing mostly.
     
  34. Alex_Heizenrader

    Alex_Heizenrader

    Joined:
    May 16, 2019
    Posts:
    86
    Trying to make Photon Voice work on Vision Pro, getting errors so far:

    "[2024-02-22T20:28:49] [ERROR] [Recorder] [PhotonVoice] Photon microphone type is not supported for the current platform VisionOS Photon.Voice.Unity.Recorder:CreateLocalVoiceAudioAndSource() Photon.Voice.Unity.Recorder:StartRecording()

    [2024-02-22T20:28:49] [ERROR] [PunVoiceClient] [PhotonVoice] [PV] OpusCodec.Encoder: System.DllNotFoundException: Unable to load DLL 'opus_egpv'. Tried the load the following dynamic libraries: Unable to load dynamic library '/opus_egpv' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen(/opus_egpv, 0x0005): tried: '/opus_egpv' (no such file) at POpusCodec.Wrapper.opus_encoder_create (POpusCodec.Enums.SamplingRate Fs, POpusCode..."

    Any solutions?
     
  35. killer_bigpoint

    killer_bigpoint

    Joined:
    Jul 11, 2015
    Posts:
    20
    If I remember correctly. Since it's an application for Apple products you have to make the DllImport use "__internal__" instead of "opus_egpv"