BUG in PUN: Specified cast is not valid

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

  • YashirYashir
    edited August 2
    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.
  • Well, I got along. Apparently the conversion from OBJECT to INT did not work properly. I have bypassed this for now.
  • We'll have a look. Sorry for the hassle and thanks for the report.
  • 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.
  • 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.
Sign In or Register to comment.