BUG in PUN: Specified cast is not valid

Options
We have a project that uses PUN to play multiplayer in Unity. At first we tried the free version and were able to work. But once we move on to the full plugin, we get stuck in the login stages. Attach the errors in the console.
We will be happy for a solution.
Thanks

THE ERRORS:
InvalidCastException: Specified cast is not valid.
Photon.Pun.UtilityScripts.CountdownTimer.TryGetStartTime (System.Int32& startTimestamp) (at Assets/Photon/PhotonUnityNetworking/UtilityScripts/Room/CountdownTimer.cs:153)
Photon.Pun.UtilityScripts.CountdownTimer.Initialize () (at Assets/Photon/PhotonUnityNetworking/UtilityScripts/Room/CountdownTimer.cs:123)
Photon.Pun.UtilityScripts.CountdownTimer.OnRoomPropertiesUpdate (ExitGames.Client.Photon.Hashtable propertiesThatChanged) (at Assets/Photon/PhotonUnityNetworking/UtilityScripts/Room/CountdownTimer.cs:116)
Photon.Realtime.InRoomCallbacksContainer.OnRoomPropertiesUpdate (ExitGames.Client.Photon.Hashtable propertiesThatChanged) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:4027)
Photon.Realtime.LoadBalancingClient.ReadoutProperties (ExitGames.Client.Photon.Hashtable gameProperties, ExitGames.Client.Photon.Hashtable actorProperties, System.Int32 targetActorNr) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2070)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3077)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at <a497a6f18e1f4b419421b940add27a6e>:0)
ExitGames.Client.Photon.TPeer.DispatchIncomingCommands () (at <a497a6f18e1f4b419421b940add27a6e>:0)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <a497a6f18e1f4b419421b940add27a6e>:0)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:208)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:142)

Comments

  • Yashir
    Yashir
    edited August 2020
    Options
    The bug is in this code:

    public static bool TryGetStartTime(out int startTimestamp)
    {
    startTimestamp = PhotonNetwork.ServerTimestamp;

    object startTimeFromProps;
    //int startTimeFromProps;
    if (PhotonNetwork.CurrentRoom.CustomProperties.TryGetValue(CountdownStartTime, out startTimeFromProps))
    {
    startTimestamp = (int)startTimeFromProps;
    return true;
    }

    return false;
    }

    If I delete this line:
    "startTimestamp = (int)startTimeFromProps;"

    the game starts well.
  • Yashir
    Options
    Well, I got along. Apparently the conversion from OBJECT to INT did not work properly. I have bypassed this for now.
  • Tobias
    Options
    We'll have a look. Sorry for the hassle and thanks for the report.
  • Tobias
    Options
    Which version of PUN do you use? If it's not a recent PUN version or PUN Classic, please upgrade to PUN 2.20.1.
  • Tobias
    Options
    I can not repro this case. We'd need the actual value and type of the property, which fails to cast to int.
    Maybe change the value of CountdownStartTime = "StartTime". This propery may be used by your code for something non-integer.
  • Sneirox
    Options
    I have a similar errors in:
    NullReferenceException: Object reference not set to an instance of an object
      at Photon.Pun.UtilityScripts.CountdownTimer.TryGetStartTime
    

    This errors happens when start built PUN Demo Asteroids project !
  • Sneirox
    Options
    Sneirox wrote: »
    I have a similar errors in:
    Everything is fine. My Scenes of Build was in wrong sequence.
  • NathanR
    Options
    Same bug described in MCR assset manual with following workaround (that works)
    Troubleshooting:
    1-The track doesn’t start and this error message
    appears in the console when a track is loaded.
    InvalidCastException: Specified cast is not valid.
    Photon.Pun.UtilityScripts.CountdownTimer.TryGetStartTime
    (System.Int32& startTimestamp) (at
    Assets/Photon/PhotonUnityNetworking/UtilityScripts/Room/Co
    untdownTimer.cs:153)
    -Open the script CountdownTime.cs in your script
    editor (spot 1)
    (Assets → Photon → PhotonUnityNetworking → UtilityScripts
    → Room → CountdownTimer.cs)
    -

    -Line 151 add PhotonNetwork.CurrentRoom != null &&
    (spot 1)
    -Remove the line 153 (spot 2)
    -Save the script (Ctrl+S)
    You must have this:
    if (PhotonNetwork.CurrentRoom != null &&
    PhotonNetwork.CurrentRoom.CustomProperties.TryGetVa
    lue(CountdownStartTime, out startTimeFromProps))
    {
    //startTimestamp = (int)startTimeFromProps;
    return true;
    }
    2-
  • NathanR
    Options
    Tobias wrote: »
    Which version of PUN do you use? If it's not a recent PUN version or PUN Classic, please upgrade to PUN 2.20.1.

    With latest version