Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Photon Unity Networking

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

  1. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Hi, I’m cross posting here, as this thread seems more active than on the photon forums. I’m looking at the suitability of PUN or perhaps the Realtime core for a turn based game.

    -
    https://forum.photonengine.com/discussion/16087/turn-based-board-and-card-games-final-stages-of-research
    -

    Hello!

    I’m researching multiplayer solutions for turn based games made with Unity.

    I am currently working on a turn based card game.

    I eventually want to update a simple turn based strategy game that I wrote way back in the pre-uNet days based on a “summer of code” tutorial by the team (brothers? Verdun creators?) that eventually became PUN, afaict. This was my latest and only attempt at networking.

    In general I have a few ‘board game over the internent” projects I’d like to work on. It’s all pro-am-as-time-allows work, so I’d like to be efficient with my research.

    I program because I need to rather than because I like to. I code as part of the work towards my end-goal. I can do it if it’s required, and I’m fairly proficient with C#, but coding is not my first focus. As such, I don’t need to reinvent the wheel for the joy of it.

    My current card game is played primarily using the Unity UI system. I move graphical elements into and out of layout groups, as the cards move around the game table, so I will need to sync gameobjects as they move in the hierarchy.

    I’ve been reading through all of the solutions I can find, including non-photon solutions, and none jump out as the obvious “right choice”.

    I feel that the best options (at least within the photon-verse) are either Realtime or PUN2, more by process of elimination than choice. Bolt seems more FPS based and Qantum more for large scale RTS games.

    I’ve yet to be drawn into Mirror, MLAPI, or any of the others; as I’m worried about the lack of support ongoing and the need to self-host, but I’m aware of them.

    On the other hand, I don’t see much in the way of turnbased tutorials for current photon products.

    There are a few notes in the Realtime docs (https://doc.photonengine.com/en-us/realtime/current/tutorials/async-and-turnbased) but nothing like a tutorial.

    The PUN turnbased tutorial (RPS...https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/rockpaperscissors-demo) has been deprecated along with (afaict) the PunTurnManager, so I’d be starting from the ground up with PUN2 as well, it seems.

    Does anyone have any concrete guidance?

    I’m willing to dig into it and find a solution, but I’d rather not start down one path and wish I’d used another.

    TiA
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    We were working on a Photon "Turnbased" as a product some years ago, right. At the core of it, was "async" gameplay features, storing and loading games/rooms. We decided to not maintain it as separate package.
    Now, the features of it are part of Photon Realtime but we don't expose the storage and loading of rooms anymore, unless needed. For this, you'd need a server to store games.

    Making a turnbased game without saving it, is quite simple (from a networking / syncing perspective). Storing games and continuing them, is more complex.


    The PUN 2 package has the PunTurnManager and it can be used as starting point for synchronous games and in general, PhotonNetworking.RaiseEvent should be straightforward to use and finish any turn based games.
    PUN should not require too much programming and I'd say you could get your game(s) going with minimal effort. Also, it may look familiar to you.
    Check out the docs. E.g. this guide about keeping state.
     
  3. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Have we missed the PunTurnManager in PUN2?

    It had looked like this was deprecated along with PUN (1), but this could have been our own mistaken assumption.

    Can we run the Rock, Paper, Scissors demo from PUN in PUN2?
    https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/rockpaperscissors-demo

    Will this be of any value? Or will we run into stumbling blocks and confusion?

    We've started looking at the PUN2 demo this morning and it seems fairly straight forward so far.

    At this point we don't need to persist games beyond one live session. I would consider saving a game state and re-entering the game hours, days, weeks later to be a bonus more than a necessity. The games we are developing would take 10's of minutes to an hour or so, but we were not planning more than one complete session at a time (at least to start).

    [edit]

    From what I've read, persisting game state and rooms has to do with using "webhooks", which I've only taken a loose glance at. These _seem_ to be available with both PUN and Realtime. For a stretch-goal, would it be possible to use these webhooks to save partial games in the future?

    [/edit]
     
    Last edited: May 11, 2020
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    @Sun-Dog, you are right: The WebHooks are required to access some storage for the room state, should you consider long running games. As long as the room's state is completely held in the event cache or in custom properties, it's relatively easy to add this feature later on. The way you get the state is the same as when a player leaves the room and rejoins (while the other is still in the room and thus keeps it open). So by implementing the ability to rejoin a room (e.g. after connection loss), you implement basic support for long running, saved games.
    PUN 2 has support for this by using the "Realtime API".

    Running the Rock Paper Scissors sample in PUN 2 is possible after you updated the demo to the changed API and new callback registration. It may be a simple project to "test" upgrading.
     
  5. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    391
    Hi Everyone.
    I am building Recovery Treatments for people with Motor and Cognitive problems through VR Video Games and I am thinking in adding to it the Asymmetric Virtual Reality function so that the patient plays in Virtual way (with the VR Headset) and their friends or family in a non-virtual way and through joysticks or cell phones interact with the patient into the same VR game with the aim of empowering and helping the patient achieve him/her goals, for it, I would need to do a multiplayer setup over the network to can make a test setup with Mobile and a PC version where I try to synchronize two players, for it, Could anybody say me how I can do it with Photon plugin?
    Hopefully you can understand me.
    Thanks for your time
     
    Last edited: May 31, 2020
  6. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    335
    Thats a very broad question. With PUN you can do this very easily. This is all straightforward and well documented in the photon docs. (*connecting the clients, without the vr part)
    One of the clients (mobile/pc) can create a room and the other one would simply just connect to the room. The player on the pc would use the vr rig (svr/ovr/whatevervr/) and the other would just be a regular controller. I would start by creating something where you connect two regular game sessions, and then convert one of the players to use vr.
     
    castana1962 likes this.
  7. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    391
    Hi rasto61
    Thanks for your advice !!!
    Best Regards
    Alejandro
     
  8. tonythedad

    tonythedad

    Joined:
    Apr 5, 2020
    Posts:
    12
  9. tonythedad

    tonythedad

    Joined:
    Apr 5, 2020
    Posts:
    12
  10. JohnTube

    JohnTube

    Joined:
    Sep 29, 2014
    Posts:
    66
    tonythedad likes this.
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    I'm happy to announce a new, bigger update to PUN 2.
    We took some time to look into ownership and transfer of control. This is more stable now and better supports ReJoin. Per player (re)entering the room, you can simply check if this is due to a rejoin (becoming active again) or a new join.
    There is a conduit to send messages (byte[] only) with pretty much no allocations going on (20 or 40 bytes at the moment, which we could not get rid of yet). This is meant for high end games, which can serialize their data accordingly and use RaiseEvent() instead of OnPhotonSerializeView().
    We are going to add docs to our manuals page in the next days.

    Let us know here, if you run into issues! We'll monitor this thread and are also active in our PUN 2 Discord. Please don't put errors reports into reviews - we can barely help through the Asset Store.

    Get PUN 2 in the Asset Store for free.
    Everyone who is still working on a PUN Classic project should consider updating. We will not support PUN Classic in Unity 2020 and up and it won't get newer features.

    If you are early in your projects, don't forget to check out SNS 2. This is still an addon (separate download for now) but developed alongside with PUN 2! It's a great set of components that provides top notch synchronization of movement, pickups, inventory and more. It supports SyncVars and does all that at a fraction of regular PUN traffic.


    v2.19 (25. June 2020)
    Fixed: FindPunAssetFolder, which relied on a file that got renamed earlier. (no new asset file version)
    v2.19 (24. June 2020)
    Added: Documentation for PhotonView.Find(ViewID).
    Added: Callback "OnPreNetDestroy" and registration to PhotonView. If necessary, scripts can get a call before networked objects get destroyed. This may help unparent/rearrange objects.
    Added: Check that the Dev Region override is in the list of available regions (from Name Server). If not, the first available region is being used.
    Changed: RegionPinger.Start() now attempts to use a ThreadPool WorkerItem to ping individual regions. Only if that fails, a separate managed Thread is used. This should help avoid running into Thread limits (if any).
    Changed: The PhotonServerSettings field "Port" now gets used, even if the client connects to a Name Server. Before, the Port was only used if the checkbox "Use Name Server" was off.
    Added: Proxy setup for WebSocket connections. To actually use the proxy settings, a special WebSocket implementation is needed. In the PUN 2 package, this value won't do anything.
    Fixed: WebSocketTcp to call peerBase.OnConnect(), as expected by all IPhotonSockets.
    Changed: Error messages for RPC issues. Not found, parameters and too many components implementing them. Now uses GO as context (click the Editor log entry to highlight the exact target object).
    Changed: OnJoinedInstantiate component to add more features. It now checks Player.HasRejoined to decide if the local player needs to instantiate networked objects or if that was done before.
    Update: The link.xml to also cover the client lib namespace ExitGames.Client.Photon. If Unity fails to run a build with the error that some default constructor is missing, move the link.xml to your project root (or merge with yours). This avoids too much code stripping in IL2CPP builds.
    Fixed: AccountService Context description override to go with the authentication token for third party registrations.
    Added: TrafficRecorder with sample. See TrafficRecorderSrc for docs and usage.
    Fixed: NullReferenceException in PhotonTeamsManager when accessed in Awake.
    Added: EnableProtocolFallback in the PhotonServerSettigns. It is enabled by default, so the client will try another protocol if the initial connect to the Name Server fails. It's only applied in ConnectUsingSettings(). This is disabled for WebGL and Xbox One. This should help with Apple reviews.
    Updated: The Realtime API and Photon3Unity3d.dll (v4.1.4.3) with lots of improvements and changes. Check the respective changelogs. Some important changes listed below:
    Improved: Performance in terms of GC. More internal objects are pooled. Events that contain just a byte[] can now be sent and received with almost zero allocations. Check LoadBalancingPeer.UseByteArraySlicePoolForEvents.
    Changed: Internals to avoid accumulation of Threads.
    Fixed: A rare threading issue for UDP connections.
    Fixed: Best Region selection for UWP builds on the .Net Runtime.
    Added: PhotonPeer.TrafficRecorder and ITrafficRecorder. This can be used to capture traffic on UDP connections.
    Added: Checks for connections on WebGL and Xbox One. Settings that can be corrected (to match the platform's requirements) are corrected with a log note. An Exception is thrown, if that's not possible. Connect methods may throw an Exception, which are to be fixed during development time.
     
    Last edited: Jul 2, 2020
    Munchy2007 likes this.
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    seldemirov likes this.
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,696
    This fix should be coming to all Unity release streams soon.
     
    tobiass and Munchy2007 like this.
  14. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    46
    Hello!
    Today i have updated my project from PUN v1 to PUN 2.19, and i'm facing some quite strange behaviour.
    I'm using Unity 2018.1.1f1.
    My networked gameObjects are destroyed through RPC:

    Code (CSharp):
    1.    public void DestroyActor(int hitmanId)
    2.     {
    3.         if (!photonView.IsMine) { return; }
    4.         if (isDead) { return; }
    5.         isDead = true;
    6.         photonView.RPC("ActorDeathRPC", RpcTarget.All, hitmanId);
    7.     }
    8.     [PunRPC]
    9.     public void ActorDeathRPC(int hitmanId)
    10.     {
    11.         PhotonNetwork.Destroy(gameObject);
    12.     }
    I'm starting the game, with me as a master client and no other clients connected. First 1-5 minutes everything is working just fine. Then i'm starting to recieve warnings:
    Code (CSharp):
    1. [Warning] Received RPC ""ActorDeathRPC"" for viewID 59 but this PhotonView does not exist! Was remote PV. Remote called. By: #01 'Player' Maybe GO was destroyed but RPC not cleaned up.
    So, some of the gameObjects are not able to recieve RPC and destroy themselves, others recieving RPCs and getting destroyed as expected.
    I've looked the trace of this warning (PhotonNetworkPart), and it seems that target PhotonView is not in the photonViewList, but removedFromLocalViewList property of the view is False. So it was added to photonViewList dictionary, was not removed from that dict, and cant be found when it recievs RPC.
    Can you please help me to solve this issue?
    Thanks!
     
  15. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    46
    Well it seems the problem is with NonAllocDictionary class.
    When there is more networked objects than NonAllocDictionary capacity, its not working whatsoever.
    And capacity can not be changed by user.
    Would be nice to see a fix asap.

    UPDATE: Emotitron from Photon support forum told me that this issue will be fixed in the next update.
     
    Last edited: Jun 29, 2020
  16. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Yes, with @Leonid 's help, we found an issue in the new NonAllocDict (used as PhotonViewCollection) and fixed that.
    There is now an update in the Asset Store: PUN 2.19.1.

    v2.19.1 (29. June 2020)
    Changed: Don't run GameObject removal code if app is quitting.
    Replaced: Mixamo animations with Standard Asset equivalents (for licensing reasons).
    Fixed: A problem in the Photon3Unity3d.dll (v4.1.4.3). New version: v4.1.4.4.
    Fixed: NonAllocDict. Capacity change was broken. This is a critical fix. PUN uses this internally for the PhotonViewCollection.
    Added: Indexer to NonAllocDict to allow Dict[key] get and set.
    Added: NonAllocDict.Clear() method.
     
    Last edited: Jul 2, 2020
    Leonid likes this.
  17. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Another issue was found and fixed:

    v2.19.2 (02. July 2020)
    Fixed: Wasn't setting owner in NetworkInstantiate, which was causing a failure to reset old owner values on second room join.

    Please update, if you use v2.19 or 2.19.1.
    Thanks for your feedback, everyone!

    Forgot to mention: There is a new compile define for PUN 2.19 to help make use of the new features, while keeping compatibility with older packages: PUN_2_19_OR_NEWER. This is available since the initial v2.19 release.
     
  18. ericleveillee

    ericleveillee

    Joined:
    Mar 30, 2020
    Posts:
    1
    Hello,

    We have been trying to disable domain reload to speed-up the editor but Photon doesn't seem to be ready for it.

    Is there any way to disable Domain reload and use Photon ?
    Are there any plan in upcoming updates to let developer use this option ?

    Thank you!
     
  19. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    It's not yet possible to do that. Disabling domain reload means we have to do a significant amount of initialization and the complete feature is still labelled "experimental".

    We plan to support it in PUN 2. The speed-up would be more than welcome.
     
    Last edited: Jul 3, 2020
  20. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    139
    I'm having an issue with PUN 2.19 (I've tested with 2.19.1 and 2.19.3, both have the same problem). Previously I was on 2.18.1, which worked fine for me. I'm using Unity 2019.4.2.

    After connecting (via PhotonNetwork.ConnectUsingSettings()) and loading a game, I instantiate some prefabs which in their Awake() add a PhotonView component to themselves. So far so good.

    Then, when disconnecting (calling PhotonNetwork.LeaveRoom() and then PhotonNetwork.Disconnect()), I'm seeing ResetOwnership() called for every PhotonView with the following callstack:

    void Photon.Pun.PhotonView:ResetOwnership() (PhotonView.cs)
    void Photon.Pun.PhotonView:ResetPhotonView(Boolean) (PhotonView.cs)
    void Photon.Pun.PhotonNetwork:LocalCleanupAnythingInstantiated(Boolean) (PhotonNetworkPart.cs)
    void Photon.Pun.PhotonNetwork:LeftRoomCleanup() (PhotonNetworkPart.cs)
    void <>c:<.cctor>b__124_0(ClientState, ClientState) (PhotonNetwork.cs)
    void Photon.Realtime.LoadBalancingClient:set_State(ClientState) (LoadBalancingClient.cs)
    void Photon.Realtime.LoadBalancingClient:Disconnect(DisconnectCause) (LoadBalancingClient.cs)
    void Photon.Pun.PhotonNetwork:Disconnect() (PhotonNetwork.cs)


    All good so far, but then ResetOwnership() is called for every PhotonView again, by which point PhotonNetwork.CurrentRoom is null and I get a null reference exception:

    void Photon.Pun.PhotonView:ResetOwnership() (PhotonView.cs)
    void Photon.Pun.PhotonView:ResetPhotonView(Boolean) (PhotonView.cs)
    void Photon.Pun.PhotonNetwork:LocalCleanupAnythingInstantiated(Boolean) (PhotonNetworkPart.cs)
    void Photon.Pun.PhotonHandler:OnLeftRoom() (PhotonHandler.cs)
    void Photon.Realtime.MatchMakingCallbacksContainer:OnLeftRoom() (LoadBalancingClient.cs)
    void Photon.Realtime.LoadBalancingClient:OnStatusChanged(StatusCode) (LoadBalancingClient.cs)
    void <>c__DisplayClass110_0:<EnqueueStatusCallback>b__0()
    boolean ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    boolean ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    void Photon.Pun.PhotonHandler:Dispatch() (PhotonHandler.cs)
    void Photon.Pun.PhotonHandler:FixedUpdate() (PhotonHandler.cs)


    I'm destroying the gameobjects with PhotonViews on them in a IMatchmakingCallbacks.OnLeftRoom() callback. This used to work, but is it no longer allowed in PUN 2.19? Am I right in thinking that you now need to make sure to destroy them before calling PhotonNetwork.LeaveRoom() and PhotonNetwork.Disconnect()?

    Thanks!
     
  21. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Edit: Re-read your post and threw away my earlier reply.

    @danger726, please send us the code how you clean up the objects.

    Apparently your cleaning-up clashes with the new workflow in PUN 2.19.3 and we need to check what exactly is happening. It will help if we know how you instantiate and destroy.
    Mail to: developer@photonengine.com.

    I overlooked your post yesterday, so: Sorry for making you wait with this issue.
     
    Last edited: Jul 8, 2020
  22. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    139
    @tobiass No worries! There's a fair amount of code involved as I built a networking wrapper layer over top of PUN which then fires off events to other parts of the game. It might be easier for me to just set up an example project that recreates the issue. Either way, I'll try and find some time to put something together to send your way.
     
  23. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    @danger726, we checked the case and the following should be a valid fix:

    Code (CSharp):
    1. /// <summary>
    2. /// Reset Owner/Controller to Creator
    3. /// </summary>
    4. internal void ResetOwnership()
    5. {
    6.     if (CreatorActorNr == 0)
    7.         SetOwnerInternal(null, 0);
    8.     else
    9.     {
    10.         // Offline Mode or just offline edge cases... just set to null.
    11.         if (ReferenceEquals(PhotonNetwork.CurrentRoom, null))
    12.         {
    13.             SetOwnerInternal(null, CreatorActorNr);
    14.         }
    15.         else
    16.         {
    17.             SetOwnerInternal(PhotonNetwork.CurrentRoom.GetPlayer(this.CreatorActorNr), CreatorActorNr);
    18.         }
    19.     }
    20. }
    It is enough to invalidate the ownership cache in this case.

    Let us know if this is correct in your case, too. If not, a repro will be welcome, thanks!
     
  24. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    139
    Hey @tobiass, I tried your fix and yes, it works fine for me, thanks!
     
    tobiass likes this.
  25. rrahim

    rrahim

    Joined:
    Nov 30, 2015
    Posts:
    189
    Hi, I noticed that Pun 1 is on sale, although you recommend using Pun 2.
    If I purchase Pun 1, is there an upgrade path to Pun 2?
     
  26. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    @rrahim, yes, there is an upgrade path.

    If you got PUN Plus Classic (v1.x) and want to update to PUN 2, please use your existing AppId with the PUN 2 Free package! All benefits carry over.

    Everyone should update to the PUN 2 version by now. The Migration Notes will help.
     
    rrahim and TokyoWarfareProject like this.
  27. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    641
    thanks I'm days away to start porting to v2. good tip.

    One question tho. I whant to upgrade the Xbox version with V1 to V2. On the token service do we need to upgrade anything?.

    What happens to older, no longer mantained versions of the game that use v1? will they lose multiplayer?

    I've a v1 based version that is on Steam that I don´t update anymore (unity 4.7) and the Xbox version that is regularly updated to latest Unity and also has kept on with the feature development. Should I buy a new license for V2 and keep the old v1 license for the non mantained? also, my xbox token service is associated to the old license id, can that be ported to any new license id?
     
  28. jstzwd

    jstzwd

    Joined:
    Oct 7, 2014
    Posts:
    5
    @tobiass Hello, I am using PUN2 in my project, however, if I purchase the on-sale PUN1 now, will the included 100 CCU of PUN1 also valid for my project?
    Also, say I create two games with Photon, and I publish them at the same time, does this included 100 CCU applied to both of them, or just one?
    If it can only be applied to one project, let's call it "A". So maybe someday, I find it unnecessary to maintain "A" because of no active players. How do I switch the available 100 CCU currently on "A" to another project "B"?
    Sorry for all these questions, thank you for your patience!
     
    Last edited: Jul 15, 2020
  29. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    @TokyoWarfareProject, authentication is the same in PUN Classic and PUN 2. Maybe minor API changes but nothing significant. Console platform support is only done via mail: developer@photonengine.com.

    Old versions of the game may still run. Old and new can co-exist via "Virtual AppIds". Means: Separated by the Game Version string, multiple groups of users may play on their own (not bothering compatibility).
    If you can disable older clients, depends on you. If needed, you can run the new version on a new AppId and disable the old one. Then, yes, existing old clients will no longer be able to connect.

    Unless you want to separate the two versions (cost-wise or other), you can run them on the same AppId.

    @jstzwd, yes, you can buy it. If you got PUN Plus Classic (v1.x) and want to update to PUN 2, please use your existing AppId with the PUN 2 Free package! All benefits carry over.

    A 100 CCU "subscription" can be applied to one title only. If you no longer want to run this title, make sure players can't use it anymore and use the AppId with the 100 CCUs for another title.
     
    jstzwd and TokyoWarfareProject like this.
  30. ksc_3899

    ksc_3899

    Joined:
    Jan 1, 2019
    Posts:
    28
    The PUN Voice SDK seems broken. It doesn't always recognize all the players in the room and is highly unstable. I've been looking at it for nearly an year now, but I see it still hasn't been fixed. Any idea on that?
     
  31. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Can you specify that more?
    Photon Voice 2 should be as stable as PUN 2. It just adds a VoiP API.
     
  32. ksc_3899

    ksc_3899

    Joined:
    Jan 1, 2019
    Posts:
    28
    Well, I have joined the room with, let's say 3 of my friends. When I speak, 1 of my friends can hear but the other can't. Sometimes I can hear the other person while they can't hear me.
     
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Ah. You refer to the actual voice part of the combo. Yes, it can be a little rough.
    Microphone access depends a lot on the platform. There are a few quirks, even though Unity covers quite a lot of the details. Anyhow: We work on it with each release. OSX support will improve in the next release. We're looking into mic issues on Galaxy phones and so on.
    It's being developed faster than ever.
     
  34. ksc_3899

    ksc_3899

    Joined:
    Jan 1, 2019
    Posts:
    28
    Yeah, I have faced the issues only with mobile devices mostly. I vaguely remember the same issue being with One Plus devices as well.
     
  35. n3eQQ

    n3eQQ

    Joined:
    Jun 22, 2020
    Posts:
    2
    Hi, I make a car game using PUN2 and I encounter a problem with synchronization my car seems to lag on remote pc.
    You can check that in my video on yt:


    Here is my CarCotroller Script with synchronization.
    Code (CSharp):
    1. public class CarControllerWithoutPhysic : MonoBehaviour, IPunObservable
    2. {
    3.     float inputX;
    4.     int width;
    5.  
    6.     static float speed = 30.0f;
    7.     float turnSpeed = 240.0f;
    8.     Vector3 direction = new Vector3(0.0f, 0.0f, speed);
    9.  
    10.     Vector3 networkPosition;
    11.     Quaternion networkRotation;
    12.  
    13.     PhotonView photonView;
    14.  
    15.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    16.     {
    17.         if (stream.IsWriting)
    18.         {
    19.             stream.SendNext(transform.position);
    20.             stream.SendNext(transform.rotation);
    21.         }
    22.         else
    23.         {
    24.             networkPosition = (Vector3)stream.ReceiveNext();
    25.             networkRotation = (Quaternion)stream.ReceiveNext();
    26.  
    27.             transform.position = Vector3.Lerp(transform.position, networkPosition, 0.5f);
    28.             transform.rotation = Quaternion.Lerp(transform.rotation, networkRotation, 0.5f);
    29.         }
    30.     }
    31.  
    32.     void Awake()
    33.     {
    34.         PhotonNetwork.SendRate = 45;
    35.         PhotonNetwork.SerializationRate = 45;
    36.         width = Screen.width / 2;
    37.         photonView = GetComponent<PhotonView>();
    38.     }
    39.  
    40.     void Start()
    41.     {
    42.         photonView = this.gameObject.GetComponent<PhotonView>();
    43.         CameraFollow cameraFollow = this.gameObject.GetComponent<CameraFollow>();
    44.  
    45.         if (cameraFollow != null)
    46.         {
    47.             if (photonView.IsMine)
    48.             {
    49.                 cameraFollow.OnStartFollowing();
    50.             }
    51.         }
    52.         else
    53.         {
    54.             Debug.LogError("<Color=Red><a>Missing</a></Color> CameraWork Component on playerPrefab.", this);
    55.         }
    56.     }
    57.  
    58.     void Update()
    59.     {
    60.  
    61.         if (photonView.IsMine)
    62.         inputX = Input.GetAxis("Horizontal");
    63.  
    64.         if (photonView.IsMine)
    65.         if (Input.touchCount == 1)
    66.         {
    67.             Touch touch = Input.GetTouch(0);
    68.  
    69.             if (touch.position.x > width)
    70.                 inputX = 1.0f;
    71.             else
    72.                 inputX = -1.0f;          
    73.         }
    74.  
    75.         transform.position = Vector3.Lerp(transform.position, transform.position + transform.TransformDirection(direction), 0.5f * Time.deltaTime);
    76.        
    77.         Vector3 euler = new Vector3(0.0f, inputX * turnSpeed, 0.0f);
    78.         transform.Rotate(euler * Time.deltaTime);
    79.    
    80.     }
    81. }
    I have a ask to you how improve this, how can I get smoothly movement of my car on remote pc. I increased SendRate and SerializationRate to 45, also I write and read position and rotation in OnPhotonSerializeView function and with Vector3.Lerp I try to assign newPosition based on currentPosition of car and networkPosition that I recived.
    Give some advice if you can. Thanks for help.
     
  36. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    641
    I would say there is no longer need to write your own lerping of data, check the photon scripts already offer interpolation options.
     
  37. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Yesterday, we released PUN 2.20.1 in the Asset Store. Here's what we worked on:

    v2.20.1 (03. August 2020)
    Fixed: An issue with Standalone builds in Unity 2019.4.x, which did not connect. The main loop was somehow not called if PhotonMono was created in RuntimeInitializeOnLoad callback.
    Changed: RuntimeInitializeOnLoad() should only happen in the Editor, where we may disable the Domain Reload.
    Removed: Code that automatically added PV to gameobjects with MonoBehaviourPun (the PhotonView is not a must-have for those scripts (but typical)).

    v2.20 (03. August 2020)
    Fixed: Potential cause for NetworkingClient being null in Editor on enter playmode. The EditorApplication.isPlaying value has a race condition.
    Fixed: Edge case where ownershipCacheIsValid was not getting correctly updated for leaving players when Cleanup is disabled.
    Added: CustomContext for PhotonWizard AccountService creation.
    Added: Some additional Standard Assets for third person demos (For SNS overlap with existing demo).
    Note: ThirdPerson scripts namespace changed to avoid conflicts with Unity Standard Assets they are taken from.
    Added: "Chat Extended" features. Properties for public channels and users. Event OnErrorInfo. Wrapped in compile define.
    Added: Additional method for finding nested components. Used by SNS.
    Fixed: PhotonView.ResetOwnership will no longer run into NullReferenceException.
    Fixed: Another potential NullReferenceException due to bad placing of a null-check (in OnEvent, case OwnershipTransfer).
    Fixed: Asteroids scenes had missing (obsolete) component on cameras.
    Added: Auto-find Observable Components in PhotonViews and Multi-select. PhotonViews can now (optionally) find observable components on the same object, making the setup easier.
    Added: Initial support to turn off Domain Reloading, also known as Fast Play Mode. Please report issues by mail, should there be any.
    Changed: InstantiateSceneObject got renamed to InstantiateRoomObject, which is a better terminology for objects that belong to the room but are not loaded with the scene. Old naming is obsolete.
    Changed: Added argument to OnControllerChange callback - controllerHasChanged.
    Fixed: Support to network-destroy scene objects (loaded with the scene). Known limit: The events to remove networked scene-objects are fired on join, not on load. This may actually desync players, depending on when scenes get loaded.
    Added: Nullcheck to the StatesGui to avoid issues when recompiling during runtime (in Editor).
    Changed: Initialization of PhotonEditor to make sure it runs for the first time after the Editor finished loading. OnInitialHierarchyChanged registers for the events.
    Fixed: Potential issue when the PhotonEditor background image could not be loaded and would assign to the style as null.
    Removed: PhotonEditor static constructor and InitializeOnLoad attribute (using InitializeOnLoadMethod exclusively).
    Removed: Support for PlaymodeStateChanged event as used before Unity 2017.2 (without the parameter). Affects PhotonEditor.cs.
     
    TokyoWarfareProject likes this.
  38. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    391
    Hi. I am building a Rehabilitation Treatment by VR Game( mainly for Oculus Quest). For the problems caused by the Covid-19, it would be very important to help to the patient from a distance, for it, one Therapist should supervise the patient, and then he/she will have to connect a Tablet to the computer (or Ipad) in order to get a view of what happens inside the VR game while the patient is using it. For that reason and sorry for my ignorance but Could I implement that Networking feature for monitoring the treatments by some Tablet or Ipad with Photon? Would it be possible? Thanks for your time. Alejandro
     
  39. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    We had to fix an oversight in v2.20. This is the new update:

    v2.20.2 (04. August 2020)

    Fixed: Destroy code that caused a "Ev Destroy Failed." error log.
     
  40. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    @castana1962, yes, you could build that with Photon. You would essentially have to create a multiplayer game where one person is just observing. You'd also need to create a backend service which only provides doctors access to the patient's session, etc.
    This topic is potentially too complex for this thread, so please mail us: developer@photonengine.com.
     
  41. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    391
    Hi @tobiass.
    What a great news for me !!!
    I sent an email to you asap
    Thanks for your support
    Regards
    Alejandro
     
  42. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    We just found that there is a sneaky bug in PUN 2.20.2, which keeps Editor instances (2019.4 and up) from syncing the scene with everyone else. This is an oversight when we added support to disable "Domain Reload" for the Editor (Fast Play mode).

    To fix it, you can change the PhotonNetwork constructor into this:

    Code (CSharp):
    1. static PhotonNetwork()
    2. {
    3.     #if !UNITY_EDITOR || (UNITY_EDITOR && !UNITY_2019_4_OR_NEWER)
    4.     StaticReset();
    5.     #endif
    6. }
     
    Last edited: Aug 18, 2020
    Munchy2007 likes this.
  43. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    Just released a new update for PUN 2. Several fixes that should not wait any longer.

    v2.21 (19. August 2020)
    Fixed: Handling of case "blocked by Windows firewall". WebSocket-sharp does not call OnError in this case. This affects WebSocket.cs.
    Updated: AuthenticationValues.Token setter to be protected internal. Only needs to be set by Photon LoadBalancing API. Updated reference docs, too.
    Fixed: Supress a minor unused warning in SlotRacer.
    Fixed: When Player disconnects - only change the owner of that players created objects if AutoCleanup is false. Otherwise, do nothing as they are all about to get destroyed, and an OwnerChange to Master could break things for some users.
    Fixed: Duplicate call to StaticReset(). This also created the LoadBalancingClient two times and caused a callback registration to get lost. This fixes the reported problem with scene synchronization in 2019.4 and up.
    Changed: PhotonNetwork.LoadLevel() methods will skip loading, if PhotonHandler.AppQuits is true. This avoids a minor issue in the Editor when a script loads a scene in OnLeftRoom() while ending playmode.
     
  44. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    There are two known issues we'll fix soon:

    WebGL exports are broken in v2.21 and fail due to not loading the WebSockeSharp lib.
    This is a mistake you can fix easily: In WebSocket.cs, the code "using WebSocketSharp;" should be below the first #else condition, making it line 8. This keeps WebGL code from requiring the dll.

    With the ability to add observables like TransformView and AnimatorView to children (previously they were restricted to the root), PhotonView.Get() has been expanded to search upwards into parent gameobjects to find the associated PhotonView for the Observable View. However, the previous change was unable to GetComponentsInParent on disabled objects. This fix works in disabled GameObjects:

    Code (CSharp):
    1. public static PhotonView Get(Component component)
    2. {
    3.         return component.transform.GetParentComponent<PhotonView>();
    4. }
    5. public static PhotonView Get(GameObject gameObj)
    6. {
    7.     return gameObj.transform.GetParentComponent<PhotonView>();
    8. }
     
  45. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    We just updated PUN 2 in the Asset Store. Lots of stuff in there:

    v2.22 (07. September 2020)

    Changed: Default observe option for PhotonView is Unreliable On Change.
    Fixed: PhotonView.Get wouldn't work if object was disabled. This fixes that.
    Fixed: PhotonView.Get was using GetComponentInParent which will fail to find the PV if an object is disabled. Custom GetParentComponent solves that problem.
    Fixed: Code using the WebSocketSharp library. It's only for non-WebGL builds and needs to be put inside the conditional code of WebSocket.cs.
    Changed: Export settings for websocket-sharp.dll. It should export to any platform (if needed) except for console, web and Windows Store. Each such platform has a more specific solution.
    Added: AmOwner property to cached ownership values.
    Added: SetControllerInternal method for use with advanced SNS ownership handling. Not used currently by Pun2.
    Changed: Photonhander for client disconnects fixed to only change owner to null rather than Master.
    Changed: Only change owner of objects that will survive autoCleanup.
    Fixed: Mispelling of Owner as Onwer.
    Changed: Only rebuild controller cache on JoinRoom if client is the master. Otherwise leaves the controller as -1 indicating the current controller isn't known yet.
    Changed: PhotonView custom inspector. Default observe option for PhotonView is "Unreliable On Change" again.
    Added: OnSerializeView now checks components, so list items being null in Observables are not breaking anymore.
    Changed: A PhotonView now has IOnPhotonViewPreNetDestroy, IOnPhotonViewOwnerChange and IOnPhotonViewControllerChange callbacks that help with fine grained control of these cases. Interface IOnPhotonViewCallback is renamed to IPhotonViewCallback.
    Realtime API:
    Added: Unity-only ConnectionHandler.StaticReset() to allow entering playmode without domain reload.
    Added: ErrorCode definition for OperationLimitReached (32743). The client will become unable to call any further operations (to safeguard the room/server) and get disconnected soon after. Currently used for SetProperties only.
    Fixed: Region pinging for the case that none of the regions answered anything. Then, all region results caused a callback.
    Added: Support for rooms that suppress room-events.
    Added: Field bool Room.SuppressRoomEvents to allow checking if room events are suppressed.
    Changed: If room events are suppressed, the callbacks OnCreatedRoom() and OnJoinedRoom() are now called by the operation response (not waiting for the suppressed events).
    Renamed: Room.SetRoomFlags() to InternalCacheRoomFlags().
    Changed: When entering a room, the local players NickName property (255) is not sent if NullOrEmpty.
    Changed: LoadBalancingApi should not use Unity.Debug unconditionally.
    Updated: AuthenticationValues reference slightly. Better wording.
    Updated: Token setter to be protected internal. Only needs to be set by Photon LB API.
    Photon DLL v4.1.4.5:
    Fixed: Serialization of a ByteArraySlice will now release it, as described in the docs. So you can pass a ByteArraySlice to RaiseEvent and control of it is passed over to the Photon API.
    Fixed: Potential issues with SupportLogger.StartBackgroundCalls() when there were 255 threads running (and or stopped).
    Changed: When PhotonClientWebSocket fails to connect, this will now correctly result in a disconnect with code/reason ExceptionOnConnect.
    Changed: The socket reading-thread not call it's disconnect method, if already disconnecting/disconnected. This avoids a surplus call (and callback).
    Internal: The thread locking object in SocketNative is no longer static.
    Note: The next release will change the native datagram encryptor api. Most likely this is the last one compatible with the old native plugin.
     
  46. w34edrtfg

    w34edrtfg

    Joined:
    Nov 23, 2014
    Posts:
    46
    Hi @tobiass ,
    This is quite weird but i suddenly started having connectivity problems with exitgames.

    Unity Editor: 2019.3.7f1 (Windows)
    PUN: v1.103.1 (30. April 2020)
    Settings:


    Even setting logging to Full/ALL Photon wasn't printing anything, so i started debugging myself and it fails to work here:


    That print is mine. Output is:


    The game was working (it has been since 2014 or so).
    As of 23-09-20 i still have this problem.
     
    Last edited: Sep 23, 2020
  47. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    91
    Hello people. I have a quite short question - what is the best way to achieve something like this?
    Code (CSharp):
    1. SendRpcToAllUsers();
    2. //wait for all of the users to receive this RPC
    3. DoSomething();
    My idea is to create an enum which holds states (WAITING, RECEIVED), serialize it among players and then check if all players state == State.RECEIVED but maybe there is some simpler way?
     
  48. michealcaj

    michealcaj

    Joined:
    Aug 18, 2017
    Posts:
    142
    PHOOOOOOOOOOOOOOTON YEHAAAA
     
  49. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,437
    @kqmdjc8: You'd need to send an acknowledgement from every player who got the RPC. There is no built-in "reply" when someone got an event, as this is overhead that's normally not needed.
    The Asteroids Demo has a waiting scene, where players signal they are "ready". That may be helpful?

    @w34edrtfg: Did you mail us? To: developer@photonengine.com. Let us know your appid and which region you connect to. Also, let us know if this is only in the Editor, the player and which platforms. Please let someone else try your build and report if it's a problem only you got.
    Did you by any chance update the Unity Editor version? I would recommend the LTS versions over 2019.3.
     
  50. w34edrtfg

    w34edrtfg

    Joined:
    Nov 23, 2014
    Posts:
    46
    Ok, i will first try to update to latest Unity version and see what happens. If i still have the problem i will send the email.
    Thanks!

    Edit: lol, updating to Unity 2020.1.6f1 fixed the issue :S
    Now time to try to switch to PUN2!

    Edit2: I've started migrating to PUN2 and there is something i missed in migration notes.
    Maybe you could add here: https://doc.photonengine.com/en-us/pun/v2/getting-started/migration-notes
    That PhotonPlayer.Find(ID) is now PhotonNetwork.CurrentRoom.GetPlayer(ActorNumber)
     
    Last edited: Sep 24, 2020
    tobiass likes this.
unityunity