InvalidCastException: Cannot cast from source type to destination type (Photon version : 1.91)

Options
Hi,
i got this error when using WebGl only , my game works fine with no errors (standalone PC Build) , but when i use WebGl build and test i got this :
InvalidCastException: Cannot cast from source type to destination type.
NetworkingPeer.AlmostEquals (System.Object one, System.Object two) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4567)
NetworkingPeer.DeltaCompressionWrite (System.Object[] previousContent, System.Object[] currentContent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4416)
NetworkingPeer.OnSerializeWrite (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4302)
NetworkingPeer.RunViewUpdate () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4118)
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:165)
i don't know is this Unity or Photon issue and i don't know what data else i can provide here , tell me and i will edit this question with new data

Best Answer

  • AhmedGoba
    AhmedGoba
    edited March 2019 Answer ✓
    Options
    i solved this problemby changing the two lines at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:(4566 , 4567) :
    from
    float a = (float)one;
    float b = (float)two;
    to
    float a = Convert.ToSingle(one);
    float b = Convert.ToSingle(two);
    yes it was casting problem

Answers

  • AhmedGoba
    Options
    sorry i foregt to mention that this error happenes only when any other player joins the room and it appears forever
  • AhmedGoba
    AhmedGoba
    edited March 2019 Answer ✓
    Options
    i solved this problemby changing the two lines at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:(4566 , 4567) :
    from
    float a = (float)one;
    float b = (float)two;
    to
    float a = Convert.ToSingle(one);
    float b = Convert.ToSingle(two);
    yes it was casting problem
  • Thank you so much, this saved my sanity and game!
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited April 2019
    Options
    Hi @AhmedGoba, @Sonicboomcolt,

    Thank you for choosing Photon and your contribution!
    (sorry for the delay)

    Could you help me investigate and reproduce this?

    Does this still happen with PUN1 versions higher than 1.91?
    Does this happen with PUN2?
    On which Unity version can you reproduce this?
    Does this happen inside Unity Editor or only in a WebGL build?

    Could you share minimal repro steps?