Search Unity

Third Party Photon Unity Networking

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

  1. KayJ_sh

    KayJ_sh

    Joined:
    Apr 14, 2019
    Posts:
    6
    Hey, I resolved the issue. Looks like Sourcetree likes to put lots of stuff in the global ignore file if you dare to add anything to it via sourcetree. Thus all *.dll have been ignored in any repo o_O
     
  2. KayJ_sh

    KayJ_sh

    Joined:
    Apr 14, 2019
    Posts:
    6
    Hi again,

    I'm working on a multiplayer game with the following setup:
    * the scene contains several playable characters and vehicles that are placed in specific positions in the scene (predefined scenario)
    * a master client opens a room
    * further clients can join at any time

    I'm currently trying to get an idea of how to usw PUN2 for that (I'm new to working with PUN2). Since I have a scene which contains the networking objects, I can't use
    Code (CSharp):
    1. PhotonNetwork.Instantiate
    to make use of automatic synchronization. What is the best approach to synch these objects?

    An idea might be to have a "Server Scene", which contains the whole scene, and a "Client scene", which contains only static objects. The dynamic objects have to be send e.g. with
    Code (CSharp):
    1. [PunRPC]
    from the server to the client. With that approach PUN won't help much since I have to reimplement lots of stuff, which comes with PUN2...

    Any idea is appreciated!

    KayJ
     
  3. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    This might sound like a bit of a strange question, but is there an easy(ish) way to prevent the automatic removal of player gameobjects (i.e. those with PhotonViews attached) when the client leaves a room.

    I assume it might be able to be done by altering one of the PUN scripts so I'm after a pointer to where would be the best place to start looking.

    [Edit] Nevermind, I found what I was looking for in PhotonNetworkPart.RemoveInstantiatedGO() function.
     
    Last edited: Mar 8, 2020
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    @KayJ_sh I have a similar setup for my RPG maps, where there are objects placed in the scenes that also need to be network synchronised at runtime.

    I found the best approach for this was to use events https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent.

    You can have the MasterClient be responsible for synchronising the objects, or if your game allows for clients to be in differing scenes/maps from each other, you can allocate a single client in each map to have the responsibility of synchronising the objects to other players in the same map.

    A beneficial side effect of this approach over using PhotonViews is that you only need to send messages between clients that are in the same scene/map as each other, which can cut down on network traffic considerably.
     
  5. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Hi, I am developing unity desktop and mobile apps.Mobile and desktop apps are not the same project (not same UI).
    Input data should be sent to desktop from Mobile devices and desktop app should display what mobile devices send.
    Mobile device might send just string data which is score or any other short string value.

    I don't have networking knowledge, So I don't know how to implement. I heard that about Photon.
    Can anybody explain me how to implement this project by using Photon?
    Is it possible to make this app using Photon?
     
    Last edited: Mar 8, 2020
  6. KayJ_sh

    KayJ_sh

    Joined:
    Apr 14, 2019
    Posts:
    6
    @Munchy2007 Thanks for your response! I only have one scene at a once with all players in the same scene (very limited amount of players).
    Could you go into further details? So you'd recommend not to use PhontonView at all?

    If I get you right, the MasterClient needs to keep a list of all objects, which need to be synchronized when a client joins. What about the scene? Same scene with all dynamic objects included for MasterClient and Client or does the client instantiate the objects with
    Code (CSharp):
    1. Instantiate
    or
    Code (CSharp):
    1. PhontonNetwork.Instantiate
    ?

    I also have controlable objects as part of the scene, like a truck, which might be controlled by any Player. How can that be achieved without using PhotonView?
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    Yes. Set RoomOptions.CleanupCacheOnLeave to false for CreateRoom().
    You should not keep rooms around for a longer time, when you enable this. The events history will be sent to joining (and returning) clients and may collect "dust" over time...

    The ideal approach to generating levels or parts of levels is doing that in a deterministic fashion. You share a seed and every client calculates the same initial world from that. Networking wise, this is lean.

    Yes, this is possible of course. Photon can be used to sync strings the way you want it.
    Follow the PUN Basics Tutorial and read the other docs. There is no tutorial to implement exactly your use case.
    Photon / PUN is for realtime interaction of players. Maybe your case could be implemented with a REST api for the clients and a website to show the data (replacing your desktop app). Just saying. I don't know your context.

    My take is that he'd advise against using PhotonViews for the sake of syncing world generation.
    The PhotonView is not streamlined for plenty of objects that are static, so it can be more effective to come up with your own, lean binary world representation instead,
    Use PhotonView for characters or units mostly.
     
  8. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    @tobiass Thanks for the tip. But as I understand it that option would prevent automatic removal of networked objects for all players in the room, whatever reason they leave, which isn't exactly what I'm after.

    What I want is to be able to do is, under certain circumstances have a player leave a room with the attendant cleanup on all the other clients. But on the client of the player that actually left the room, I'd like to retain the networked gameobjects in the scene. I'd expect to have to manually remove photonviews etc. and I also wouldn't be doing anything 'networky' on that client following this.

    Yes, that was the intention behind my post.
     
    Last edited: Mar 10, 2020
  9. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Out of the box, Unity 2019.3.3, fresh install, direct from PUN website, following PUN's own documentation (https://doc.photonengine.com/en-us/pun/current/getting-started/initial-setup) ... and I immediately get a crash inside PUN's code from an unhandled NRE.

    Any suggestions? This has to be something simple! This line crashes:

    Code (CSharp):
    1. public static bool ConnectToMaster(string masterServerAddress, int port, string appID)
    2.         {
    3.             // TODO: refactor NetworkingClient.LoadBalancingPeer.PeerState to not use the peer but LBC.connected or so
    4.             if (NetworkingClient.LoadBalancingPeer.PeerState != PeerStateValue.Disconnected)
     
  10. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Ah ... figured it out. Docs are missing one key point: "this library crashes unless you're in play mode". Sigh.
     
  11. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Another bug ... if you try to join a room twice, you get an incorrect error message:

    "JoinOrCreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: Joining). Wait for callback: OnJoinedLobby or OnConnectedToMaster."

    ...which is especially confusing when you're doing the join from within the callback "OnConnectedToMaster".

    (error message is wrong, and should state "...and make sure you are not already in that room", since "Wait for callback:" is simply not sufficient a condition to avoid this error)
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    I can see where this may be useful but so far, it's not a buit-in feature. It can be done locally but requires changing PUN somewhat. At the moment, I would have to say you are on your own doing this. The source is there but I know it can be a overwhelming to get into a system like PUN.
    If you look into this and have questions, please mail or PM, ok?

    Oh. Now I got what you mean. Yes, PUN is built for the play mode / runtime. Not in-Editor usage. PUN depends on components and such, as it's specifically a package to make multiplayer games.
    In PUN 2, the Realtime API is in a separate folder and can be used easily without much of the integration that PUN does. It's more a regular C# API and thus it may be better suited. Use a LoadBalancingClient to start a connection.

    If you like this fixed, please share the code snippet that caused the issue.
    If you call JoinOrCreateRoom() in the callback OnConnectedToMaster(), it should work.

    PUN is only available in the Asset Store, afaik. Do you mean that?
     
  13. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    That's fine, just would have been good to have 1 sentence in the getting started info. The errors you get when you try to run it from Editor mode aren't obviously connected - and you can follow the guide precisely and get these unexplained errors.

    It's as simple as you can imagine.

    Class 1:

    Code (CSharp):
    1. [ContextMenu("Manually trigger a connect")]
    2.     public void Connect()
    3.     {
    4.         PhotonNetwork.ConnectUsingSettings() )
    5.     }
    6.  
    7.     public override void OnConnectedToMaster()
    8.     {
    9.         base.OnConnectedToMaster();
    10.      
    11.         Debug.Log("OnConnectedToMaster callback: Attempting join room...");
    12.         PhotonNetwork.JoinOrCreateRoom(
    13.             "room1",
    14.             new RoomOptions(),
    15.             null
    16.         );
    17.     }
    Class 2:

    Code (CSharp):
    1.  
    2.     public override void OnConnectedToMaster()
    3.     {
    4.         base.OnConnectedToMaster();
    5.      
    6.         PhotonNetwork.JoinOrCreateRoom(
    7.             "room1",
    8.             new RoomOptions(),
    9.             null
    10.         );
    11.     }
    ...result: error message saying I should be calling that method in OnConnectedToMaster. Um, no. The problem is that I'm already in the room / joining the room.

    Yep, was just making clear I wasn't downloading some old, deprecated version or somethhing :).
     
  14. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    PS: apart from those very small issues around intro docs, I'm finding it very easy to work with and quick to get stuff going so far, which is great.
     
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    Good point. Noted.

    So you implemented OnConnectedToMaster() in two scripts and both are in the scene?
    Then the problem is not that the client is already in a room but it's already "joining". In that sense, yes, the error is misleading but so is the duplicate implementation of the callback.
    But I do get your point of course. Thanks for the input. The check is oversimplified but I think this can be fixed.

    Thanks for saying so! I hope PUN can make up for wasting some of your time initially.
     
  16. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Yes - a dumb mistake! - but the kind of thing that happens especially when you're starting with a new framework :).

    Hasn't wasted any time! I expected to need a day or two in getting the concepts in my head etc, so if anything it's been much quicker than expected.
     
  17. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Thanks @tobiass, I guessed as much and I've already had a root around in the PUN scripts and I think I've found a likely place to start looking at making some changes.

    If I get stuck I'll let you know.
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @Munchy2007, yes, let me know when you get stuck. I think it may be as easy as adding an option and skip some cleanup. Maybe you have to distinguish between the local player's networked objects and remote ones.

    @a436t4ataf : Good to read that!
     
    Munchy2007 likes this.
  19. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    @tobiass , I've just discovered the EventData passed to the IOnEventCallback function OnEvent has a value of -1 for the EventData.Sender property when PhotonNetwork.OfflineMode is true.

    Is this intended behaviour? As it breaks code that otherwise works when not in offline mode. Logically, I'd expect the sender ID to 1 in offline mode.

    I've implemented a workaround for the time being, so it's not a major problem if it isn't going to be changed, but I thought I'd ask anyway, in case there's a good reason for it to be -1 that I'm missing.
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @Munchy2007, I'll have to check. If it's -1, then it's not intentionally so. You get this when you send to all?

    Edit: Did you CreateRoom()? If not, the player's ActorNumber is still -1 (which indicates not being in a room).
     
  21. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    @tobiass , yes, this is after I have created and joined a room, and only happens when PhotonNetwork.OfflineMode is true.

    this is an example of how I might raise an event
    Code (CSharp):
    1.     public static void SendToAll(PUNEventCode eventCode, object eventContent, bool sendReliable, bool buffered = false)
    2.     {
    3.         var options = RaiseEventOptions.Default;
    4.         options.TargetActors = null;
    5.         options.Receivers = ReceiverGroup.All;
    6.         Debug.Log($"Actor No: {PhotonNetwork.LocalPlayer.ActorNumber}\nIn Room: {PhotonNetwork.InRoom}");
    7.         Send(eventCode, eventContent, sendReliable, options, buffered);
    8.     }
    9.  
    10.     private static void Send(PUNEventCode eventCode, object eventContent, bool sendReliable, RaiseEventOptions options, bool buffered)
    11.     {
    12.         options.CachingOption = buffered ? EventCaching.AddToRoomCache : EventCaching.DoNotCache;
    13.         var sendOptions = new SendOptions();
    14.         if (sendReliable) sendOptions.DeliveryMode = DeliveryMode.Reliable;
    15.         PhotonNetwork.RaiseEvent((byte)eventCode, eventContent, options, sendOptions);
    16.     }
    17.  
    and it results in a debug log result of:-

    Actor No: 1
    In Room: True

    which is what I would expect.

    However, in my event handler class (simplified example)
    Code (CSharp):
    1. public class NetworkEventHandler : MonoBehaviour, IOnEventCallback
    2. {
    3.     public void OnEvent(EventData photonEvent)
    4.     {
    5.         Debug.Log($"photonEvent.Sender: {photonEvent.Sender}");
    6.     }
    7.  
    8.     protected virtual void Awake()
    9.     {
    10.         PhotonNetwork.AddCallbackTarget(this);
    11.     }
    12.  
    13.     protected virtual void OnDestroy()
    14.     {
    15.         PhotonNetwork.RemoveCallbackTarget(this);
    16.     }
    17. }
    I get the following debug output when in offline mode:

    photonEvent.Sender: -1

    It's quite possibly a result of some misunderstanding on my part of the way events are raised, in which case hopefully you can tell me what I'm doing wrong.
     
    Last edited: Mar 23, 2020
  22. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Has anyone else had issues recently with RPC's? I have a random issue where my RPC is going off for the person who created the game, but it's not being received by all the other players for some reason. Yet he can get theirs. And shortly after the game creator tried he gets dc'ed I think from the master server as his game creations are not visible. Weird little bugs and I can't figure out what's causing them. My other project has the exact same code but no issues.

    Code (CSharp):
    1. [SerializeField]
    2.     private Text chatField;
    3.     [SerializeField]
    4.     private string chatTextToSend;
    5.     public void onChangeSendChatText()
    6.     {
    7.         chatTextToSend = PhotonNetwork.NickName + ": " + this.GetComponent<InputField>().text + "\n";
    8.         this.GetComponent<InputField>().text = "";
    9.         base.photonView.RPC("sendChatMessage", RpcTarget.All, chatTextToSend);
    10.     }
    11.     [PunRPC]
    12.     void sendChatMessage(string chatTextToSend)
    13.     {
    14.         chatField.text += chatTextToSend;
    15.     }
    Edit, also if anyone knows why the player's info has a number in front of it when fetched and displayed in a text field I would be grateful for said knowledge. I'm assuming it's a database or index purpose.
     
  23. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @Foestar, I don't see a problem with the RPC at all but then again, I didn't use your "setup" either. I don't have the scene, so I set the chatTextToSend = "<NickName>: <Input>\n". Next, I simply log something in the RPC method: Debug.Log(chatTextToSend). Last but not least: I put this as component on an object with a PhotonView and made it react to onClick. It works locally and remotely just fine.
    You need to be in a room to fire the RPC, even if the networked object is loaded with the scene.

    In doubt, enable the SupportLogger and it will log the important steps during matchmaking and show in which room you're in.

    The Player.ToString() has a number as the nickname is often null or empty. In Photon context players in a room are uniquely identified by the ActorNumber, which is what's included in ToString().


    @Munchy2007, I checked your case and found a few things to fix with PUN 2's offline mode. Can you wait until early next week for the update or should I send it in a direct message?
     
  24. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Ah, I figured that's what it was with the number addition to the string.

    As for the RPC issue, at this point I'm thinking it has to do with how my host player is connecting because both are literally using the same code placed on an input field that includes a photonview and it's acting differently for the person who created the game than everyone else. And the only difference between the two at this point is that one created the game and the others joined.

    So going back and looking I don't actually have the player who creates the game ever join the lobby. I did this because I read that you only need to do that when trying to see games/rooms. Other than that, that's the only difference between the two clients which is why I am so confused as to it not working as intended. Especially when every other client who connects have no problems going to and from each other and the host, but can't receive the hosts themselves.
     
  25. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    @tobiass I can wait until it's released. It's not currently causing me any major headaches as I found a simple workaround for the time being.

    Thanks for looking into it.
     
    tobiass likes this.
  26. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Okay, after several hours of going through and trying to fix it I gave up on finding the issue and made a separate scene to test RPC's. It contained a simple text field that handled the success or failure of callbacks starting with a connection to the main server, then the lobby, and then creating and joining a room. So far success.

    Added an input field with a photon view on it and attached a script that actually handled the callbacks as well as sent information from the InputField to the text field via RPC. Thus I have a scene with only 2 gameobjects and 1 has a script. Load scene, test out, RPC's running as expected.

    So in short, some how I got tangled in my other scene I guess because somewhere along the way the host seems have issues. Gonna revamp my main menu scene. I'm sure I'll have it working in no time.
     
    tobiass likes this.
  27. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @Foestar: Oha. Glad you could get things working in a tester but it's of course annoying as heck you got stuck in the actual project...
    I think there was once a case where I had to re-do a prefab. Maybe it was linking to an instance of a component (rather than a prefab's component) or such. No idea what really happened.
    Good luck!
     
  28. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Yeah not really sure what the case was. I went back and made the player join the lobby after a main server connection and suddenly I had no issues. So everything went fine with it after that.

    I am however having another odd one where the OnPlayerEnteredRoom callback isn't going off as intended. A simple script containing just the code below doesn't seem to want to fire off the debug when a player joins. It is marked MonoBehaviourPunCallbacks, and has the required usage at the start to allow said callbacks.
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections.Generic;
    5. using Photon.Pun;
    6. using Photon.Realtime;
    7.  
    8. public class PlayerListing : MonoBehaviourPunCallbacks
    9. {
    10.     [SerializeField]
    11.     private GameObject playerListingPrefab;
    12.     [SerializeField]
    13.     private Transform playerListContent;
    14.  
    15.     #region PUN 2 Callbacks
    16.     public override void OnEnable()
    17.     {
    18.         //first we need to clear the list of any prior player listings
    19.         //from previous games
    20.         foreach (Transform child in playerListContent)
    21.         {
    22.             GameObject.Destroy(child.gameObject);
    23.         }
    24.         //then we trigger our refresh list function
    25.         refreshPlayerListing();
    26.     }
    27.  
    28.     public override void OnPlayerEnteredRoom(Player newPlayer)
    29.     {
    30.         Debug.Log(newPlayer + " has entered the damn room");
    31.     }
    32.     #endregion
    33.  
    34.     private void refreshPlayerListing()
    35.     {
    36.         //this adds a player listing prefab for every player in the list
    37.         foreach (var playersName in PhotonNetwork.PlayerList)
    38.         {
    39.             //create the players name object
    40.             var newPlayerListing = Instantiate(playerListingPrefab, playerListContent);
    41.             //and set the players name
    42.             newPlayerListing.gameObject.transform.GetChild(0).GetComponent<Text>().text = playersName.NickName;
    43.         }
    44.     }
    45. }
    46.  
    47.  
    I do use the same callback in another script and it works fine within the same scene. I don't know why this specific one isn't. But I'll keep playing with it until I get it.
     
    Last edited: Mar 27, 2020
  29. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    I figured it out! It still isn't working with the above code because for whatever reason the OnEnable messes with the following code. If I cut that section out the player entering the room sets off the Debug, but not if the OnEnable stays in. I'm not sure, I guess I must be using the OnEnable wrong? Or I'm missing something? Either way, that is what is causing the issue with it not going off.

    If I have to I can just fire off a function from the button presses prior UI. But the enable feature seemed too good to pass up.
     
  30. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    PUN v2.17 is now in the Assetstore!
    There is a new feature called "Dev Region", which hopefully helps everyone with testing. After first run in Editor, all development builds use a fixed region, so that Best Region selection can't go wrong on one device and get you into inexplicable matchmaking issues. Of course this can be disabled easily (remove the entry in the PhotonServerSettings).

    There are plenty of fixes and other improvements.

    v2.17 (26. March 2020)

    Added: New "Dev Region" feature. With this setting, all development builds will use the same region, avoiding initial matchmaking problems with best region selection. Development builds are turned on automatically, when the PhotonServerSettings get created initially and the "Dev Region" is set on first run in Editor.
    Changed: PhotonServerSettings inspector to accomodate the new values and reorganize existing ones.
    Changed: Instantiate and InstantiateSceneObject to not create a new object while not (yet) in a room. This avoids issues where an invalid showed up. There is a new debug log for this case, as it causes null-reference exceptions (in case it's used incorrectly).
    Added: New animations for the Basics Tutorial. The previous ones were causing warnings on import / reload.
    Added: New callback OnErrorInfo when the client receives an ErrorInfo event from the server. Implemented in MonoBehaviourPunCallbacks and SupportLogger.
    Changed: PhotonNetwork.SetPlayerCustomProperties return bool instead of void.
    Internal: ObjectsInOneUpdate will now initialize the capacity of a SerializeViewBatch.
    Fixed: Unity Cloud Builds. A check prevents creation of ServerSettings when using Cloud Build.
    Internal: The PhotonEditor can now define a "customToken" for the AccountService registrations.
    Changed: Utility script OnJoinedInstantiate. It is now more versatile.
    Updated: SocketWebTcp.cs which should no longer define a SerializationProtocol. This is now part of the inherited class IPhotonSocket and automates sending the used protocol. You may have to edit files existing in your project.
    Fixed: PunTurnManager ignores processed event callback when sender is -1, so that it can be instantiated even when player is not in room.
    Updated: Better warning for Trigger usages in PhotonAnimatorView inspector and at runtime.
    Updated: The Realtime API and Photon3Unity3d.dll (v4.1.3.0) with lots of improvements and changes. Check the respective changelogs.
     
    Foestar and Munchy2007 like this.
  31. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    In other news:

    We've been busy getting "Simple Network Sync 2" for PUN 2 ready for everyone.
    SNS 2 is a set of components which fit into PUN 2 and get you way more synchronization features and much better results than PhotonTransformView and co.
    The tickbased synchronization gives you much better results on remote machines, covers pickups, mounts, grounding on moving platforms and SyncVars right in PUN 2!

    In case you missed it, there is now a Photon Discord Server. Chat, get news, ask quick questions and discuss with us and everyone else!

    SNS 2 is also being discussed on Discord. Join the "Simple" channel.
     
    Jimaniki, Foestar and Munchy2007 like this.
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    That's probably it. When using MonoBehaviourPunCallbacks, you need to call:
    base.OnEnable();
     
  33. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    I noticed that PhotonNetwork.cs has 2.16 as the PunVersion
    Code (CSharp):
    1.         /// <summary>Version number of PUN. Used in the AppVersion, which separates your playerbase in matchmaking.</summary>
    2.         public const string PunVersion = "2.16";
    Is this an oversight and is it safe for me to change it to 2.17?
     
  34. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    You nailed it. I missed the base.OnEnable();

    Omg! That's actually awesome and big news! I found that the transform view seemed a bit off and I relied on outside syncing code. It will be nice to have something with a good tick rate to go with an already solid foundation! Gonna have to read the above GitHub in a bit.
     
    tobiass likes this.
  35. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    It is! And It's safe to edit. Will roll out a minor update asap. Thanks for spotting this!
     
    Last edited: Mar 27, 2020
    strecher and Munchy2007 like this.
  36. strecher

    strecher

    Joined:
    Mar 21, 2020
    Posts:
    2
    Hello,

    this is my first time working with PUN. I found a tutorial on YouTube which explains how to create a simple multiplayer with Photon. But here the function "OnConnectedToMaster()" and after that "OnJoinedLobby()" is used.
    Neither of these two functions is called as explained. It is not executed at all.
    Is it no longer active in the current version? Are there alternatives?

    Thanks and LG
    rstre
     
  37. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    @tobiass

    I've noticed that I'm getting this warning in the log when a game build is played:-

    Plugins: Failed to load 'D:/Program Files (x86)/Steam/steamapps/common/Game Folder/Game_Data/Plugins/PhotonEncryptorPlugin.dll' with error 'The specified module could not be found.

    As far as I'm aware it isn't causing any problems but does it suggest that is something not quite right with my installation/build and if so do you have any suggestions for what needs to be done to fix it?

    Many thanks
     
  38. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    Plugins: Failed to load '.../Plugins/PhotonEncryptorPlugin.dll' with error 'The specified module could not be found.

    This error is harmless (but I agree that it should not get logged in that case).
    Background: We try to load a native dll for encryption and if that's not available, a managed API is used instead. This is handled internally and not to worry.
     
    Munchy2007 likes this.
  39. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Okay, thanks for confirming that I can ignore it.
     
  40. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    Hi, I have a car that will spawn on the scene, and you can control it. But the only thing that can control it is who created the scene, and who joined it can not do it. Help please
     
  41. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    We just released v2.18 with a lot of changes under the hood. Some performance tweaks and fixes. Also, compatibility with Unity 2019.3 is fixed and 2020 should also work (even though beta and still a moving target). Some changes are under the hood in the other changelogs (Realtime and library).

    v2.18.1 (30. April 2020)
    Fixed: String serialization issue
    in the Photon3Unity3d.dll (v4.1.4.0). Updated to Photon3Unity3d.dll (v4.1.4.1). Characters that needed more than one byte in UTF8 failed to send.
    v2.18 (28. April 2020)
    Fixed: Support for Unity 2019.3. As Unity 2020 is still beta, there may be more import / build issues. Please report via mail.
    Note: We noticed upgrading projects may create more than one PhotonServerSettings file. If your AppId seems gone, look up these files and keep the one with settings.
    Fixed: Asteroid Demo bullet instantiation uses the position sent via the rpc, instead of the current local position.
    Updated: Nicer format for the countdown utility script to avoid floating points.
    Fixed: NullReferenceExceptions in PhotonTeamsManager.OnPlayerEnteredRoom and PhotonTeamsManager.OnPlayerLeftRoom.
    Added: PhotonTeamsManager.GetTeamMembersCount which is a helper method to get size of teams directly.
    Fixed: Photon teams extension methods for team assignment now rely only on Player.SetCustomProperties.
    Fixed: Removed obsolete usage of GuiLayer Components in demos for compatibility with Unity 2019.3 onwards.
    Fixed: Some warnings that Unity was showing on build.
    Changed: The checks before sending operations. As long as the peer is switching servers, there is no connection and operations can not be sent. This is logged better.
    Added: Logging of OnJoinRoomFailed to SupportLogger.
    Changed: StripKeysWithNullValues to reuse a list of key with null-values. This causes less allocations and garbage to clean.
    Fixed: Setting the serialization protocol for connections that directly go to the Master Server. This was broken in v2.17 by accident.
    Changed: The assembly PhotonWebsocket (WebSocket folder) will no longer export to UWP / Windows Store builds, even if the compile define WEBSOCKET is set. It is simply incompatible with the platform.
    Changed: LoadBalancingPeer.ConfigUnitySockets() will not set the UDP/TCP sockets for Windows Store builds.
    Changed: RegionHandler.GetPingImplementation will no longer use PingMono class, unless it is defined by some platform-specific code.
    Updated: The Realtime API and Photon3Unity3d.dll (v4.1.4.0) with lots of improvements and changes. Check the respective changelogs.
     
    Last edited: Apr 30, 2020
    Jimaniki likes this.
  42. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    This should be fixed in PUN 2.18, by the way.
     
    Munchy2007 likes this.
  43. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Thanks for letting me know, I'll update to 2.18 sometime in the next few days and check it out.
     
  44. atomlg

    atomlg

    Joined:
    Feb 11, 2013
    Posts:
    6
    Hello @tobiass, I have last update v2.18.1 (30. April 2020) and Unity Unity 2019.3.12f1. But I have problems, Unity and photon work the same, but In all scripts where I use photon libraries Unity don't see them and I have errors. In 2019.3.11f1 all is fine
     

    Attached Files:

    Last edited: May 1, 2020
  45. net8floz

    net8floz

    Joined:
    Oct 21, 2017
    Posts:
    37
    Same as atomlg
     
  46. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    Last edited: May 4, 2020
  47. net8floz

    net8floz

    Joined:
    Oct 21, 2017
    Posts:
    37
    Oh thank you for the link actually this helped me solved, as you can probably guess, other issues my project was having. I've rolled back to 2019.3.11f - sorry for the bother and thanks again for the link.
     
  48. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    Seems like the Visual Studio not able to find Photon.Pun assembly in 2019.3.12f is definitely a Unity bug rather than a Photon bug: https://forum.unity.com/threads/2019-3-12f1-visual-studio-2019-problem.879724/

    You can workaround this issue by creating a script "VSFix_2019312.cs" anywhere in your project Assets/ folder as follows:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. public class VSFix_2019312 : AssetPostprocessor
    6. {
    7.     private static string OnGeneratedCSProject(string path, string content)
    8.     {
    9.         return content.Replace("<ReferenceOutputAssembly>false</ReferenceOutputAssembly>", "<ReferenceOutputAssembly>true</ReferenceOutputAssembly>");
    10.     }
    11. }
    12.  
     
    Last edited: May 6, 2020
  49. spicybat

    spicybat

    Joined:
    Jul 28, 2019
    Posts:
    3
    Hi all, I'm having an issue with JoinRoom().

    I'm in the process of making a room where players can join by roomName, but I'm having some issues that I'm wondering if anyone has the answer to. I'll create a room with a random name and will try to join that room on a different device and it won't join and call OnJoinRoomFailed.

    Here are snippets of how I create/join a room:

    Create:
    Code (CSharp):
    1.  
    2. RoomOptions roomOptions = new RoomOptions();
    3. roomOptions.IsVisible = false;
    4. roomOptions.MaxPlayers = maxPlayersPerRoom;
    5. roomOptions.IsOpen = true;
    6. PhotonNetwork.CreateRoom("" + Random.Range(10000, 99999), roomOptions, null);
    Join:
    RoomName is the random number created above.

    Code (CSharp):
    1.  
    2. PhotonNetwork.JoinRoom(roomName, null);
    3.  
    I find it odd that if I set my visibility to true, I can join a room using JoinRandomRoom but not JoinRoom(name). Any ideas?
     
  50. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068