Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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,021
    Some more PUN 2 notes:
    It seems there is an issue with Android exports, where an outdated native plugin is required. This logs an error and fails. You can comment-out the code as workaround (doubleclick the error log to get there).
    Also: We thought that the new TransformView component is better to sync positions but it after submission, it turned out that it's worse than other solutions in some cases. So: We will update the TransformView in one of the next updates.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    @Shadowing: No, in Photon Chat you can't rename channels as the name is the ID of it.
    @Smart-hawk1: Only the "controller" of a PhotonView can send the updates. For all others, the stream is in "read mode".
     
  3. imgumby

    imgumby

    Joined:
    Nov 26, 2015
    Posts:
    122
    "Existing subscriptions (e.g. of a previously purchased PUN Plus) can be used with PUN 2. There is no upgrade fee or such! If you got an existing 100 CCU subscription, you can use that. Existing AppIDs can be used in PUN 2 (and vice versa)."

    That's a bit confusing at least for my coffee starved mind.Are you saying we as license holders of PUN + 1.9.1 we can use the free PUN 2 version license to get the added benefits of the paid PUN 2 ?? I'm a license holder of PUN + and don't see the usual upgrade path......errr....why not simply let us do a free upgrade to PUN2 like normal..??
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    I meant to say that the benefit you got from PUN 1 Plus is the subscription, which you can continue to use with PUN 2 Free (or even with PUN 2 Plus). You are not losing anything by switching to the Free package.
    If I recall correctly (and my coffee starved not-too-far-from-going-home brain might fool me), we couldn't offer the upgrade, as we would lose the ability to update PUN 1. I think that the upgrade basically marks the end of the updates for an existing product?
    And once you upgraded (in the store) you could not simply go back and get the old package, much less one with newer fixes.
    We can do that this way. We really wanted to packages to be separated, so we don't accidentally force anyone into updating the project. Maybe we underestimated the willingness to update :)
     
  5. imgumby

    imgumby

    Joined:
    Nov 26, 2015
    Posts:
    122
    I think you'll find not many willing to pay a $95 update fee..We are used to seeing free updates per the asset stores sellers contract . Unless you're saying PUN2 is an entirely new product from the ground up and can justify it I don't think it meets the criteria therein for a paid upgrade.....good luck:cool:
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    @imgumby: We have to make this more clear in the package itself but the upgrade path for PUN 1 Plus is not to buy PUN 2 Plus (for technical/store reasons). If you used PUN 1 Plus (or Free) and want to update to the PUN 2 package, just get the Free package.
    The PUN 2 Plus package is only there in case you are working with PUN 2 and didn't get a subscription before. In that case, if you want to get a subscription, buy PUN 2 Plus.

    Is that making sense, when explained that way?
     
    Last edited: Aug 28, 2018
    hopeful likes this.
  7. IsntCo

    IsntCo

    Joined:
    Apr 12, 2014
    Posts:
    146
    Thanks Tobias - so its sort of like a "1.5" version since there aren't any new features? Its primarily a refactor, new demos, and more organization of file structure? Just want to clarify as to tangible improvements so people can temper their expectations. We always get excited about a new major version, so I just want to be clear on what to expect. In short, its more like a "new" version of PUN, as opposed to a major shift? Thanks for the work, Tobias! :)
     
  8. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Is upgrading a project as simple as deleting the old PUN folders, importing PUN2 and then fixing all the script errors?

    Ignore this, see my next post below.
     
    Last edited: Aug 28, 2018
  9. imgumby

    imgumby

    Joined:
    Nov 26, 2015
    Posts:
    122
    Better I guess...seems a little convoluted but as long as it works same as PUN2+ I'm fine with that.I bought PUN+ ages ago for a game that just didn't come to life and a new project I'm working on will probably try to institute MP because it's just a good selling point for more genres than I would have thought of before...
    thanks
     
  10. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Just upgraded my game in development to PUN2. Took about 2.5 hours to fix all the script errors, but the only thing I haven't worked out yet is how to convert this:-

    NetworkingPeer.onOperationResponse.AddListener(OnNetworkinPeerOperationResponse);


    I use this to check the result of a CAS operation to set a room property:-

    PhotonNetwork.CurrentRoom.SetCustomProperty("allocatorID", _newId, currentID);


    I can't find NetworkingPeer if it still exists.

    Can you tell me how I'd go about this with PUN2?

    That aside, all the other changes were quite obvious and straightforward, and the game ran first time after the conversion with no errors, which quite honestly was astonishing :)

    If I manage to work out the NetworkingPeer issue I'll edit this post, otherwise I could do with a nudge in the right direction.
     
    Last edited: Aug 29, 2018
  11. codeDoc

    codeDoc

    Joined:
    Feb 12, 2014
    Posts:
    6
    Migration works for me except i couldnot figure out alternative for
    Code (CSharp):
    1. PhotonNetwork.autoCleanUpPlayerObjects
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    Right, it's a new version of PUN, not a major shift. We think the system works well for a lot of cases and we wanted to keep that.

    @imgumby: Glad I could clear this up! You won't be missing anything with the PUN 2 Free package. It's the same content as Plus.

    @Munchy2007: Cool to know you could upgrade (mostly). The networkingPeer is gone. The tasks it was used for are either directly in the PhotonNetwork class or in the PhotonNetwork.NetworkingClient.
    What you did before, could be achieved as: PhotonNetwork.NetworkingClient.OpResponseReceived += this.OnOpResponse; The OnOpResponse being: public void OnOpResponse(OperationResponse obj).
    What do you do with the OperationResponse? Maybe you could use another callback?

    PhotonNetwork.CurrentRoom.SetCustomProperty is "correct" to use CAS, yes.

    @codeDoc: PhotonNetwork.autoCleanUpPlayerObjects was removed. The setting is per room, so it's now in the RoomOptions. Minimally, this would be: PhotonNetwork.CreateRoom(null, new RoomOptions() { CleanupCacheOnLeave = true });.
     
  13. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Hi Tobiass, thanks for the info, that looks like just what I was after.

    I use it (rightly or wrongly) to check the result of the CAS operation above when I try to set the room property. Basically it's so a user can generate a unique ID to allocate to a gameobject that he instantiates for some (but potentially not all) of the clients, to act as a unique identifier. The CAS operation is to ensure that two or more clients making a request for an ID at the same time, can't end up being allocated the same ID.

    However, it's occurred to me since yesterday that I could possibly have used AllocateViewID to achieve the same purpose and then UnAllocateViewID after I'm finished with it. But as this would be a fairly common action, especially in a busy room, there is the very real possibility of running out of ViewIDs after not very long. (If I'm right that unallocating a ViewID doesn't make it available to be re-used.)

    I'm aware that I can increase the number of ViewIDs at the expense of the total amount of player connections, but to be on the safe side I'd have to raise the ViewID max so high it would seriously restrict my player limit.

    With my own system I face no such restriction as the ID allocated can be re-used.

    If there's a better way to check the result of a the room SetCustomProprty CAS operation (without using webhooks), I'd be grateful if you'd be able to point me in the right direction.

    Many thanks

    Edit: On further reflection, I've just examined how your AllocateViewID function works, and I'm thinking I can use a similar method to make my own IDs. I'll have a play around with that idea first and see how I get on.

    Edit2: Actually, now having looked at the AllocateViewID/UnAllocateViewID code properly, I can see that unallocated ViewIDs will eventually be re-used. So I can actually just use AllocateViewID/UnAllocateViewID.

    I really should do more investigation before I post :p

    However, I'd still be interested in the best way to check a CAS operation result, should the need actually ever arise.
     
    Last edited: Aug 29, 2018
  14. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Hello, i purchased pun+some years ago and never got round to using it. I am however starting a multiplayer game now and see you recommend using PUN2 + . You also state the 100 ccu can be used with PUN2+ but how do i get PUN2 from the asset store?

    Many thanks

    Daniel
     
  15. imgumby

    imgumby

    Joined:
    Nov 26, 2015
    Posts:
    122
    If you look up a few posts you'll see I asked a similar question and the answer that follows.Apparently you can use your old PUN1 license with the free version of PUN 2... unless I read wrong of course..:confused:
     
    tobiass likes this.
  16. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,630
    Thanks so much for that explanation! I was wondering what was going on, and that makes it perfectly clear.
     
    tobiass likes this.
  17. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    I want to make a copy of a GameObject in my scene that has a PhotonView attached and I'm using Instantiate(original). I don't want the copy to be network aware so I'm removing the PhotonView as soon as the copy has been instantiated.

    However, I get an error PhotonView ID duplicate found: 1002. New: View (0)1002... etc.

    This is what I'm doing to make the copy.
    Code (CSharp):
    1.  
    2. var go = Instantiate(originalObjectWithPhotonView);
    3. DestroyImmediate(go.GetComponent<PhotonView>());
    4.  
    So despite immediately destroying the PhotonView, it still manages to check for duplicates and log the error.

    I've stopped the error now by changing the LogError to a LogWarning in PhotonNetworkPart.cs and returning,
    Code (CSharp):
    1.  
    2. if (netView != listedView)
    3. {
    4.     Debug.LogWarning(string.Format("PhotonView ID duplicate found: {0}. New: {1} old: {2}. Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.", netView.ViewID, netView, listedView));
    5.     return;
    6. }
    7.  
    which as I understand it retains the original entry rather than replacing it with the new one. As far as I can tell everything seems to work okay now, but I just wanted to check that what I've done won't cause any problems in situations where a duplicate viewID is created and then immediately destroyed. If this is okay, I'll update the log warning text to better reflect what's actually happening.

    Edit: I've refined the above and added a static Boolean allowDuplicateViewIDs to PhotonNetwork. When set, it ignores the check for duplicates and just returns with no error. It automatically sets itself back to false to re-enable the default behaviour.

    So any time I want to clone a gameobject as described above, I just set PhotonNetwork.allowDuplicateViewIDs to true first.

    Edit2: I've since discovered that this introduces some subtle bugs where under some circumstances objects become controlled by the scene instead of the player. So I've abandoned this approach and implemented something that doesn't require cloning an existing object with a PhotonView.
     
    Last edited: Sep 2, 2018
  18. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I just started with Photon this week, and everything was going swimmingly until an hour ago. But now, all of a sudden, I can't get two clients (both sitting on my desk) to connect to the same room.

    I've tried both JoinRandomRoom (with no parameters) plus CreateRoom (with empty string), as well as JoinRoom("WTF") plus CreateRoom("WTF"):

    Code (CSharp):
    1.     public override void OnConnectedToMaster() {
    2.         Debug.Log("OnConnectedToMaster() was called by PUN.");
    3.      
    4.         Debug.Log("CountOfPlayersOnMaster: " + PhotonNetwork.CountOfPlayersOnMaster
    5.             + "; CountOfPlayersInRooms: " + PhotonNetwork.CountOfPlayersInRooms
    6.             + "; CountOfRooms: " + PhotonNetwork.CountOfRooms);
    7.  
    8.         //        PhotonNetwork.JoinRandomRoom();
    9.         PhotonNetwork.JoinRoom("WTF");
    10.     }
    11.  
    12.     public override void OnDisconnected(DisconnectCause cause) {
    13.         Debug.Log("OnDisconnected(" + cause + ")");
    14.     }
    15.  
    16.     public override void OnJoinRandomFailed(short returnCode, string message) {
    17.         Debug.LogWarning("OnJoinRandomRoomFailed(" + returnCode + ", " + message + ")");
    18.         PhotonNetwork.CreateRoom("");
    19.     }
    20.  
    21.     public override void OnJoinRoomFailed(short returnCode, string message) {
    22.         Debug.LogWarning("OnJoinRoomFailed(" + returnCode + ", " + message + ")");
    23.         Debug.Log("Creating room 'WTF'...");
    24.         PhotonNetwork.CreateRoom("WTF");
    25.     }
    26.  
    27.     public override void OnJoinedRoom() {
    28.         Debug.Log("OnJoinedRoom!  I am actor number " + PhotonNetwork.LocalPlayer.ActorNumber
    29.             + ", and there are " + PhotonNetwork.CurrentRoom.PlayerCount + " player(s), including me");
    30.  
    I run this one one client, and see:
    Then, leaving that one running of course, I launch the same code on the other machine, and I get exactly the same thing. Each client has cheerfully created and joined its own room with the same name, denying all knowledge of the other.

    Again, this was all working fine until earlier today. Then it stopped. I have no idea what changed.

    EDIT: After much logging, I've discovered that they are connecting to different regions — one client is using region 'usw' while the other is using region 'us'. Different regions -> different master servers -> sad Joe.

    I connect using PhotonNetwork.ConnectUsingSettings(). In my settings, the server and port are left blank, and I haven't set any region filters. These machines are literally six inches apart, and connected to the same WiFi router. Why are they going to different regions?
     
    Last edited: Aug 31, 2018
  19. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    If you have the region selection set to auto, the program pings each region server the first time it runs and joins that server. It also saves that server in playerprefs, so subsequent sessions will be to the 'best' server it found on the first run.

    It sounds to me like the two PCs somehow ended up saving different region servers, but you can reset this by selecting menu Window->Photon Unity Networking->Highlight Server Settings and then in the server settings inspector click the reset button next to Best Region Preference. For PCs without the Unity editor installed clearing all playerprefs should also reset the region preference.

    Hope this helps.
     
    tobiass likes this.
  20. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Thanks, that must be what happened. Wow, what a silly way to lose half a day. :(

    For now I've just set the Fixed Region to 'usw'. For the sake of development, we'll want our whole team (which is rather distributed) accessing the same server anyway. Just need to remember to clear it again before we ship.
     
    Munchy2007 likes this.
  21. dashasalo

    dashasalo

    Joined:
    Oct 7, 2016
    Posts:
    11
    Hi, I can't seem to get Asteroid demo from PUN2 package to work. DemoAsteroids-GameScene scene loads fine and all clients confirm they loaded the level but the countdown timer callback never gets called. Any idea why that might be?

    Solution:
    Attached CountdownTimer script to a game object in the scene and it works perfectly now.
     
    Last edited: Sep 2, 2018
  22. ThySpektre

    ThySpektre

    Joined:
    Mar 15, 2016
    Posts:
    362

    Could you make a new prefab (design time) that is a non-networked version of your normal object without a PhotonView and Instantiate that instead?
     
    Munchy2007 likes this.
  23. ThySpektre

    ThySpektre

    Joined:
    Mar 15, 2016
    Posts:
    362
    What is the best coding practice regarding Photon.Instantiate with player objects that have script that are only run on the local machine (ie move scripts, camera follows, etc.)? I have currently been adding these to the prefab object in the editor with these components disabled and then enabling them at run time only for the local player.

    Would it use less bandwidth to leave these script components off the prefab and use AddCompnent<> to add them only to the local player?
     
  24. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    That's pretty much what I've ended up doing. The issue arose because it's quite a complicated gameobject setup which doesn't exist as it is in the game until at runtime, and just cloning the object at runtime would have been a handy shortcut.
     
  25. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    303
    the project im currently working on is 8 player each with a fast moving object over a small area, in this case it's best to use PUN or BOLT ?
     
  26. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Hello and sorry if this is a duplicate, new to PUN as i am migrating from Unity networking.

    I am going over the demo " Demo Asteroids", looking to learn about the lobby system implemented here.

    For my game i am looking for the abilities to join a random game and create a game.

    If i create a room with a build of the demo, the random mode works fine and the player connects to the room. But if i create a room and try to find the room by clicking the list button it doesnt show the created room.

    Just wondering if anyone else is aware of this or know why it isnt working?

    Newbie to PUN and trying to understand the API but to fresh to know where the bug maybe in the demo supplied. Otherwise this is perfect functionality for the game i have in mind.

    Thanks and look forward to the replies.

    Best

    Daniel
     
  27. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Also one other question.. my player is going to based on only 2 players. So is it best to get Pun or Bolt?

    Thanks
     
  28. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    Yes, the 100 CCU get attached to an "AppId" and you can use that in all variants of PUN, no matter which.
    So you can simply get the PUN 2 Free package. It has the same content as the PLUS package.

    Will have a look if we should update the package to fix this.

    The way you do it, is fine. It does not affect the bandwidth, as clients only tell one another, which prefab to instantiate (no matter how many components they have). In PUN 1.xy, you can have one or more components implement void OnPhotonInstantiate(PhotonMessageInfo info), which gets called when the object gets network-instantiated.

    Is it a physical object or is the movement "arcade-style", where you could jump and reverse instantly?
    How important is precision and can you hide, if the engine cheats a bit?
    In general: Fast and precise movement is very tough, cause you can't hide lag very well.
    Please reply via mail: developer@photonengine.com

    You are right, there is a bug in the Asteroids demo! We forgot to change the demo, when we removed the "Auto Join Lobby" feature from PUN 2. The idea is that you'd only join the lobby when needed (and not automatically, by accident) but then we forgot to do just that. :(

    In LobbyMainPanel.SetActivePanel(string activePanel), you can do a quick hack to get this working:
    Replace the line with RoomListPanel.SetActive... with this:
    Code (CSharp):
    1. if (activePanel.Equals(RoomListPanel.name))
    2. {
    3.     RoomListPanel.SetActive(true);
    4.     PhotonNetwork.JoinLobby();
    5. }

    Both can be good for a 2 player game. Is it a shooter or would you benefit from other Bolt features? Then use Bolt. Do you know either already, then use that.
     
  29. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    Update!
    As of PUN v2.0.1, the Asteroids Demo is fixed.


    Asteroids Demo Fixes

    It seems, the Asteroids Demo is broken in the initial PUN 2 release. We will submit a new package but here are the fixes for everyone being quicker:

    The "Show Room List" stays empty. You should join a lobby. In best case, on UI Button click. So: modify LobbyMainPanel.OnRoomListButtonClicked() to include if (!PhotonNetwork.InLobby) PhotonNetwork.JoinLobby(); and make the button OnClick action call OnRoomListButtonClicked().

    The player list doesn't work. In the DemoAsteroids-LobbyScene, find the GameManager in the hierarchy. Add the prefab "PlayerOverviewEntry" to the Player Overview Entry Prefab field.

    Ships won't be spawned. In the DemoAsteroids-LobbyScene, find the GameManager in the hierarchy. Add a CountdownTimer component (in Utilities) and put the hierarchy object "InfoText" into the Text field.
     
    Last edited: Sep 4, 2018
  30. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    @tobiass The game will be a coop 2 player shooting game. I have been trying to figure out the best approach and i am totally new to PUN and BOLT. So not sure whats the best at this point.

    Thanks for the Fix, i will try it now and let you know how i get on. Cheers

    Daniel
     
  31. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Fix works, created a new UI button and hooked it up all good listing appear so super cool. I couldn't get Asteroid to work but not concerned here as i will be writing my own logic. Thanks for the support and fast turnaround! appreciated
    Best

    Daniel
     
  32. anunnaki2016

    anunnaki2016

    Joined:
    Jun 16, 2016
    Posts:
    93
    hi all i need your help please

    I have a big problem ;(

    Master become invisible after join room, from which I build 3 or 4 objects can you help me please?

    check the video you can see the problem



    Received OnSerialization for view ID 1001. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined

    i have trie this but nothing changed ;(

    https://doc.photonengine.com/en-us/pun/current/getting-started/feature-overview#_messageQ

    If i build one item or two is work no error no master invisible, if i build 3 or 4 item i get the bug after join room again
     
    Last edited: Sep 3, 2018
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    Difficult to say. Bolt has a few nice features for shooters, which may save you some work. Using PUN will probably require some more effort from you, to hide lag and or get correct results for shots. On the other hand: It's coop, so you can cheat a little as long as it's fair.
    In the end: Both products have been used for shooters, so it's more up to you, which approach makes more sense for your coding / expectations.

    @anunnaki2016: I don't get the problem. I don't know what I see there.
    Run the SupportLogger component with the code and check the logs after the problem happens.
     
  34. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    We just released a tiny update of PUN 2, to fix the issues in the Asteroids Demo.

    v2.00.1 (4th September 2018)
    Updated: Asteroids Demo. Fixed room listing, player listing, the ready-button and the countdown for ship instantiation.
    Added: A "teleport" setting to the PhotonRigidbody2DView and PhotonRigidbodyView. With this, you can implement teleporting as done in the Asteroids Demo.
    Changed: When the PhotonServerSettings point to a Master Server, ConnectUsingSettings() will re-set the serialization protocol (SerializationProtocolType) to be compatible with the Photon Server SDK.
     
  35. Steviebops

    Steviebops

    Joined:
    Apr 9, 2013
    Posts:
    132
    Im getting a whole bunch of errors like this
    "is marked as an override but no suitable method found to override"

    Im on Editor version 2018.2.0f2, do I need to use a different version of Unity for PUN 2?
     
  36. gregorioramos

    gregorioramos

    Joined:
    May 22, 2018
    Posts:
    9
    I'm having a problem, now the following error message always shows up. Even in previous versions of the project that used to work. I even tried to change the AppID. Any ideas how to fix it?
    I am using the PUN 2 Unity asset. I updated the project from PUN 1, before updating I was 100% sure that I removed all files from PUN 1.
    I just created a new project with simple logic using PUN 2 and it worked just fine...
    I'm using Unity 2018.1.1f1

    Exception: startCommand.fragmentsRemaining was 0 but not all fragments were found to be combined!
    ExitGames.Client.Photon.EnetPeer.ExecuteCommand (ExitGames.Client.Photon.NCommand command) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:1839)
    ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:413)
    ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1422)
    Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:126)
     
  37. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I've got a beef with PhotonNetwork.InstantiateSceneObject: it's not checking for the presence of a custom object pool before demanding that the prefab be found in a resources folder.

    If it would just skip that check (at least in this case), everything would be fine, because my object pool absolutely does have the requested object. There's no need for it to be in a Resources folder. But InstantiateSceneObject bails out before even trying.

    It's an easy fix, but of course I'm loathe to change the Photon code unless there's a good chance future versions will have the same fix. What do you think? Can we bypass the prefab-must-be-in-Resources check when using a custom object pool?

    EDIT: I guess another possibility for me is to just add my objects to PhotonNetwork.PrefabCache. That might do it...
     
  38. Timboc

    Timboc

    Joined:
    Jun 22, 2015
    Posts:
    234
    Hi! I'm running v 2.0.1 (latest) in 2018.1.9f2 and I'm using Photon realtime between a PC (TCP) and WebGL project.
    Everything seems to be working beautifully (even sending images via byte[]).. with one exception.
    I'm calling an RPC to pass an integer and a float and I'm receiving crazy overflow numbers just for the float.

    Code looks like the following with logging set to max in case the TCP << 48.. is useful.

    Debug.Log("Float variable broadcasting change to: " + val);
    photonView.RPC("VariableChanged_Float", RpcTarget.Others, idx, val);

    [PunRPC]
    public void VariableChanged_Float(int variableIndex, float val)
    {
    Debug.Log("Float variable RECEIVED change to: " + val);
    }
    //////output PC ////// Float variable broadcasting change to: 5.9
    //////output WebGL////// TCP << 48 = F3-04-C8-00-02-F5-68-00-04-62-05-62-06-62-04-7A-00-02-69-00-00-00-09-66-CD-CC-BC-40-62-02-69-FC-2D-9D-1B-62-00-69-00-00-00-01-FE-69-00-00-00-02
    //////output WebGL////// Float variable RECEIVED change to: -4.293612E+08


    Any help would be greatly appreciated - many thanks in advance.
     
  39. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    I can't reproduce this on 2018.2.5f1. Weird.
    Did you update an existing project? Is this maybe related to older code?

    Will have to test this one.

    Ow. Good catch.
    Instantiate and InstantiateSceneObject should both make use of the ObjectPool. If there's a pool, the resources folder should not be relevant.
    If you can work around this for the time being: Cool. We will need a few days to find and test a solution.

    This is very weird. So you say you don't run into this when you use a new, empty project but you run into this in your updated one?
    Fragments are used when there is a large message, which needs to be send in multiple UDP packages. They need to be reassembled, which seems to fail here. So far, I could not reproduce this, even sending a lot of data.
    Does this happen all the time or infrequently?
     
    Last edited: Sep 5, 2018
    JoeStrout and Timboc like this.
  40. gregorioramos

    gregorioramos

    Joined:
    May 22, 2018
    Posts:
    9
    It only happens in the updated project.
    it did not happen at first, it started only now. Even in previous commits of the project, which worked previously, it continues. I tried rebuilding the library, changing the AppID, everything. It happens every single time when I am not the master client. I have absolutely no clue on why this is happening
     
    Last edited: Sep 5, 2018
  41. Steviebops

    Steviebops

    Joined:
    Apr 9, 2013
    Posts:
    132
    It is an updated project, not a clean one, if that helps.
     
  42. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    80
    Hello everyone!

    I'm currently testing PUN 2, and I use the
    PunTurnManager
    class because it's a turn based online game. But the
    Start()
    method of the
    PunTurnManager
    is not implemented anymore, and I results to a crash of my application.

    I didn't see any mention to this in the migration note, can you give me more information about this?
     
    Last edited: Sep 6, 2018
  43. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    Maybe you can try the following (just to check one potential cause):
    In the LoadBalancingClient constructor, we set the SerializationProtocolType. For WebGL, it's SerializationProtocol.GpBinaryV16, while it's GpBinaryV18 for everything else. You could check what happens when you only use GpBinaryV16.

    @Noxalus: Hm, yes, this doesn't look completely updated. We will update this asap.


    Thanks everyone for feedback and reports.
    We will do our best for fixes and quick updates.
     
  44. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    429
    Hi,

    Good catch, this is fixed internally and will be in the next update, meanwhile, you can get the file attached to this post.

    let us know how it goes.

    Bye,

    Jean
     

    Attached Files:

    hopeful likes this.
  45. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I'm having trouble with ViewIDs and my custom object pool. In brief: they're never getting reused, so after playing a while, I run out of them and Photon breaks.

    It's quite possible I'm doing something wrong, but I'm not sure how it's supposed to work. PhotonNetwork.RemoveInstantiatedGO contains this code:
    Code (csharp):
    1.  
    2.             if (ObjectPool != null)
    3.             {
    4.                 PhotonView[] photonViews = go.GetPhotonViewsInChildren();
    5.                 for (int i = 0; i < photonViews.Length; i++)
    6.                 {
    7.                     photonViews[i].ViewID = 0;  // marks the PV as not being in use currently.
    8.                 }
    9.                ObjectPool.Destroy(go);
    10.             }
    Note that it's not calling UnAllocateViewID; it's simply setting the ViewID to zero. Then my object pool's Destroy method gets invoked, but obviously it's impossible to unallocate the view ID there, because it's already been set to zero. And if I try to unallocate it before calling PhotonNetwork.Destroy (which would require some real gyrations anyway), Photon gives me an error along the lines of "you can't unallocate this ViewID because it's still in use."

    So, it's clear why the view IDs are never getting reused... but how are they supposed to work in this case?
     
  46. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    The automatically assigned viewIDs don't need to be unallocated. This covers anything using PhotonNetwork.Instantiate(), even when using an ObjectPool.
    PUN is using the viewIDs in sequence and just makes sure that the new number isn't used. It will wrap around when it hits the cap, so there's a good chance "old" numbers are no longer in use.

    Only when you manually allocate viewIDs, you have to unallocate them.
     
    JoeStrout likes this.
  47. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    303
    Does OnPhotonSerializeStream send data if the gameobject is not active?
     
  48. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Do I need to include Assets\Photon\PhotonLibs\Photon3Unity3D.pdb in my GitHub repository, or can it be safely left ignored?
     
  49. Rob-161

    Rob-161

    Joined:
    Dec 1, 2016
    Posts:
    20
    Hi, can someone tell me what would be the equivalent for the bottom script when using PUN2? I am stuck on this one.
    public void OnEnable()
    {
    PhotonNetwork.OnEventCall += OnEvent;
    }

    public void OnDisable()
    {
    PhotonNetwork.OnEventCall -= OnEvent;
    }

    Thanks.
     
  50. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    You need to implement IOnEventCallback and register for callbacks, something like this should do it

    Code (CSharp):
    1. using Photon.Pun;
    2. using UnityEngine;
    3. using Photon.Realtime;
    4. using ExitGames.Client.Photon;
    5.  
    6.  
    7. public class NetworkEventHandler : MonoBehaviour, IOnEventCallback
    8. {
    9.     public void OnEvent(EventData photonEvent)
    10.     {
    11.         // Do event related Stuff
    12.     }
    13.  
    14.     void OnEnable()
    15.     {
    16.         PhotonNetwork.AddCallbackTarget(this);
    17.     }
    18.  
    19.     void OnDisable()
    20.     {
    21.         PhotonNetwork.RemoveCallbackTarget(this);
    22.     }
    23. }
     
    Last edited: Sep 10, 2018
    tobiass likes this.