Photon errors only on standalone build

Options
Hey guys I've ran into some weird errors with Photon, however only on standalone built and no issues when playing from Unity.
UnloadTime: 0.420928 ms
NullReferenceException: Object reference not set to an instance of an object
at PingCloudRegions.Awake () [0x00000] in :0
UnityEngine.GameObject:Internal_AddComponentWithType(Type)
UnityEngine.GameObject:AddComponent(Type)
UnityEngine.GameObject:AddComponent()
PhotonNetwork:.cctor()

(Filename: Line: -1)

NullReferenceException: Object reference not set to an instance of an object
at NetworkingPeer..ctor (IPhotonPeerListener listener, System.String playername, ConnectionProtocol connectionProtocol) [0x00000] in :0

at PhotonNetwork..cctor () [0x00000] in :0
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork

and so on and so on

what could be the issue?

Comments

  • waxx
    Options
    After updating to newest version I'm receveing similar errors, only though upon class compilation from dll
    not via unity playing

    loading 35 unused Assets to reduce memory usage. Loaded Objects now: 1157.
    Total: 1.247742 ms (FindLiveObjects: 0.047538 ms CreateObjectMapping: 0.032494 ms MarkObjects: 0.693524 ms DeleteObjects: 0.165182 ms)

    UnloadTime: 0.384823 ms
    NullReferenceException: Object reference not set to an instance of an object
    at PhotonNetwork..cctor () [0x00000] in :0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork
    at PhotonHandler.FallbackSendAckThread () [0x00000] in :0

    at ExitGames.Client.Photon.SupportClass+<>c__DisplayClass1.b__0 () [0x00000] in :0

    (Filename: Line: -1)

    Unloading 7 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)

    Unloading 25 unused Assets to reduce memory usage. Loaded Objects now: 3725.
    Total: 1.113550 ms (FindLiveObjects: 0.126669 ms CreateObjectMapping: 0.040317 ms MarkObjects: 0.641773 ms DeleteObjects: 0.033999 ms)

    NullReferenceException: Object reference not set to an instance of an object
    at PhotonNetwork..cctor () [0x00000] in :0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork
    at PhotonHandler.FallbackSendAckThread () [0x00000] in :0

    at ExitGames.Client.Photon.SupportClass+<>c__DisplayClass1.b__0 () [0x00000] in :0

    (Filename: Line: -1)

    NullReferenceException: Object reference not set to an instance of an object
    at PhotonNetwork..cctor () [0x00000] in :0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork
    at PhotonHandler.FallbackSendAckThread () [0x00000] in :0

    at ExitGames.Client.Photon.SupportClass+<>c__DisplayClass1.b__0 () [0x00000] in :0

    (Filename: Line: -1)

    NullReferenceException: Object reference not set to an instance of an object
    at PhotonNetwork..cctor () [0x00000] in :0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork
    at PhotonHandler.FallbackSendAckThread () [0x00000] in :0

    at ExitGames.Client.Photon.SupportClass+<>c__DisplayClass1.b__0 () [0x00000] in :0
  • Tobias
    Options
    Please import the latest PUN (currently v1.61) into a new, empty project and use one of the demos to try to reproduce the issue. Use the same setup (PhotonServerSettings) as in your current project.

    If you can reproduce it, let us know the Unity version you use, your system, etc. Anything that helps us reproduce this.
  • AngelX
    AngelX
    edited October 2015
    Options
    Hello. I have the same issue.
    I created new Scene (not project) dont know if it matters. and created there Canvas with 1 Button and 1 Text element to see the log (on Android it's hard to debug especially when this error reproduces only on standalone build.) This is my Only script using in that scene.
    using UnityEngine; using UnityEngine.UI; using UI; using System; public class PhotonTest : MonoBehaviour { public Text text; // Use this for initialization void Start() { } // Update is called once per frame void Update() { } public void OnClick() { this.ConnectToLobby(); } public void ConnectToLobby() { try { text.text += "\r\n" + "Connecting... using "+ Config.Global.version; PhotonNetwork.ConnectUsingSettings(Config.Global.version); text.text += "\r\n" + "Connected using "+ Config.Global.version; } catch (Exception ex) { text.text += "\r\n" + ex.ToString(); } } }

    On using at Unity or PC build its work fine but APK on android is giving that:
    Connecting... using 0.1.0 System.TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork ---> System.NullReferenceException: Object reference not set to an instance of an object at PhotonNetwork..cctor () [0x000e6] in D;\Projects\unity\game\Assets\Photon Unity Networking\Plugins\PhotonNetwork\PhotonNetwork.cs:1077 --- End of inner exception stack trace --- at PhotonTest.ConnectToLobby () [0x0002b] in D;\Projects\unity\game\Assets\Scripts\UI\test\PhotonTest.cs:28

    Using:
    PUN v1.62 (13. October 2015)
    Unity Personal 5.2.1f1

    PS: if this is a PUN free limitation
    i think you should change the description text on it's package
    Export to almost all platforms. iOS and Android exports require Unity 5 or Unity 4 Pro with mobile license.
    I read this like i must have Unity 5 PERSONAL or Unity4 pro + mobile
  • Tobias
    Tobias admin
    edited October 2015
    Options
    This is not a limitation of PUN Free.
    To export PUN to mobile (Android / iOS), you need to use either Unity 5 or get PUN+ if you use Unity 4.

    I will have to take a look at Unity 5.2.1f1. It might be a regression bug in the export. We had those before.

    On a Button, I expect that OnClick is exclusively called by the UI input, well after everything was setup. That's weird.
    @AngelX: Your issue is on Android, not in the Standalone?


    To test this, please also import PUN into a new, empty project and try the demos for your platforms. If those show the same issue, I can more easily reproduce them.
    You can also update Unity and see if that helps.
  • Tobias
    Options
    I updated my previous post, @AngelX, @waxx.
    Not sure if you got a note about that.
  • AngelX
    Options
    To test this, please also import PUN into a new, empty project and try the demos for your platforms.
    I used new Scene not project. Does it matters? i described total instruction what i did and how to reproduce. Just use my code in a new scene and you can get reproduce it.

    PS: its doesn't reproduce in Testing mode like using it in Android emu or connected to PC device with "Build and run". Only reproduces in complete android apk downloaded on device and installed on it.

    PSS: Sry for my English. Not a native language.
  • Tobias
    Options
    The PS makes a big difference. For testing, I usually don't do that workflow.
    Does it reproduce when you deploy with Unity but then start the game again (after forcing it to close)?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @AngelX

    We are unable to reproduce the error you described. It may not be related to the one described by the OP.
    Please do as Tobias said previously: create new Unity project, import PUN, configure using wizard (or highlight PhotonServerSettings) and open DemoHub scene to be able to test all PUN demo scenes.

    Same thing applies to @waxx.
  • AngelX
    Options
    To test this, please also import PUN into a new, empty project and try the demos for your platforms
    its Doesn't reproduce. Looks like its my own trouble then. Ill spend some time to investigate it. Thx for your help and quick answer.
  • sushanth
    sushanth
    edited February 2022
    Options

    Facing same issue. It occurs in Android build. photonView is null in OnClick() method of UI button.

     void Start()

      {

        photonView = GetComponent<PhotonView>();

        Debug.Log("Photon View : " + photonView.IsMine);

      }


    //OnClick() method of a UI Button.

      public void OnFire()

      {

        Debug.Log("Fire Button Clicked : " + photonView.IsMine); //Null Reference Occurs here.

        if (photonView.IsMine)

        {

          Debug.Log("Is this printing?");

          sphereType = Random.Range(0, spherePrefabs.Length);

          sphereVelocity = gameObject.transform.forward * (sphereType + 1) * 5.0f;

          Debug.Log("Calling RPC");

          photonView.RPC("ShootARSphere", RpcTarget.All, sphereVelocity, sphereType);

        }

      }

      [PunRPC]

      void ShootARSphere(Vector3 vel, int index)

      {

        GameObject sphere = Instantiate(spherePrefabs[index], firePoint.transform.position, firePoint.transform.rotation);

        Rigidbody sr = sphere.GetComponent<Rigidbody>();

        sr.velocity = vel;

        Destroy(sphere, 3.0f);

      }



    PS: The script is attached to a gameObject containing Photon View component.



    EDIT : (Resolved my issue) I was adding the prefab's script method to OnClick event of my UI button. Instead I should add the method of the prefabs's instance in the scene at runtime.

    Was not related to Photon at all.