ConnectUsingSettings and PingImplementation


In my Unity project I use a custom c# library to abstract networking (photon/steam).

This library references the LoadBalancingApi I compiled from the DotNet SDK.
This library instantiates a LoadBalancingClient and calls AddCallbackTarget(this) to receive notifications.

When I call ConnectToRegionMaster(region) I get OnConnectedToMaster as intended.

Now if I want to use ConnectUsingSettings instead, in order to pick the best region, OnRegionListReceived gets called but I get an exception right after: RegionHandler.GetPingImplementation() fails to CreateInstance of type because the type is null. Because UNITY_SUPPORTED is not defined in LoadBalancingApi then LoadBalancingPeer.PingImplementation gets never set.

Is this supposed to happen? what did I miss? is there any _extensive_ documentation regarding ConnectUsingSettings and the events we are supposed to answer to?



  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @eaudinet,

    Thank you for choosing Photon and for your report!

    What is the SDK you are using? PUN or Unity SDK?
    Which version?

    Could you share the full stack trace of the NullReferenceException?

    What Unity version is this?
    What target platform is this?
    What scripting backend is this?
    What mono/.NET version is this?
    UNITY_SUPPORTED is not defined in LoadBalancingApi
    It is, on top of each file in Unity context:
    #if UNITY_4_7 || UNITY_5 || UNITY_5_3_OR_NEWER

    Meanwhile I'm reviewing both places in the code where we set ping implementation:



  • Hi,

    SDK is photon-dotnet-sdk_v4-1-2-20
    Unity version is 2019.3.2
    Target platform is Windows Editor/Standalone 64 (and will need Standalone OSX and Stadia)
    Scripting backend is Mono (and will need IL2CPP)
    Api Compatibility level is .Net 4.x

    As mentionned I do compile the PhotonLoadBalancingApi project from the DotNetCloudSdk solution from the photon-dotnet-sdk_v4-1-2-20 archive.
    Since it is compiling a standalone library, none of the UNITY_XXX preprocessor definitions are defined.. therefore UNITY_SUPPORTED cannot be defined.
    Then RegionHandler.GetPingImplementation() will throw an exception when attempting to get a ping implementation from a LoadBalaningPeer.PingImplementation that is null.

    RegionHandler.cs (344)
    ping = (PhotonPing)Activator.CreateInstance(LoadBalancingPeer.PingImplementation);

    This is the organization of assemblies:
    Unity Project Assemblies --> Custom Proprietary 'abstraction' Assemblies --> PhotonLoadBalancingClient Assembly --> Photon3DotNet Assembly
    Shall I edit the project properties in order to set a UNITY_5 define? Is it expected practice to let us tweak the project properties at all?
  • We usually assume that the LoadBalancing API is copied into the Unity project as source, rather than as dll. So when you compile it externally, yes, the Unity defines will be missing.
    Even if the Unity define is null, the RegionHandler should select a suitable Ping implementation. Maybe the problem here is that Unity's code stripping hit once more: It will remove PingMono if it's usage is hidden somewhere in the dlls.

    Try this: Set thte LoadBalancingPeer.PingImplementation = typeof(PingMono) and run.

    You said you use the .Net SDK from our page. Is it the Unity labeled one?
    Even if you only need/want the LoadBalancing API, I would probably getting it via the PUN 2 package from the Asset Store. The API is included in the PhotonRealtime folder. A benefit is that the Asset Store gives you a ping when we update the package. Then you can look up the changes conventiently.
  • eaudinet
    edited March 2020
    When getting the SDK on your website I picked Product=Realtime, Engine|Framework|Platform=.Net Language=C# so I expected a standalone C# assembly that does not depend on Unity, otherwise I would have picked Engine|Framework|Platform=Unity...

    When you suggest I set LoadBalancingPeer.PingImplementation = typeof(PingMono), you mean I do that in the LoadBalancingPeer.cs file and recompile the assembly? Because that member is protected internal and I cannot change it from the outside. Unless I derive the LoadBalancingPeer just for that purpose... [edit] no I can't derive the LoadBalancingPeer it is a private member the LoadBalancingClient is instantiating in its constructor
  • What if I copy the LoadBalancingApi files in my photon-matchmaking-and-networking-implementation project and add "SUPPORTED_UNITY" in the project properties?