OnPhotonSerializeView() issue ? Not working with two variables
Options
i am working on a multiplayer game using photon.
i am streaming the data using using OnPhotonSerializeView
everything is working fine for one variable.
like
if (stream.IsWriting)
{
stream.SendNext(carController.BrakeInput);
}
else if(stream.IsReading)
{
carController.BrakeInput = (float)stream.ReceiveNext();
}
but when I use 2 variables then it gives the error - not working anymore
if (stream.IsWriting)
{
stream.SendNext(carController.BrakeInput);
stream.SendNext(carController.skidding);
}
else if(stream.IsReading)
{
carController.BrakeInput = (float)stream.ReceiveNext();
carController.skidding = (bool)stream.ReceiveNext();
}
i am streaming the data using using OnPhotonSerializeView
everything is working fine for one variable.
like
if (stream.IsWriting)
{
stream.SendNext(carController.BrakeInput);
}
else if(stream.IsReading)
{
carController.BrakeInput = (float)stream.ReceiveNext();
}
but when I use 2 variables then it gives the error - not working anymore
if (stream.IsWriting)
{
stream.SendNext(carController.BrakeInput);
stream.SendNext(carController.skidding);
}
else if(stream.IsReading)
{
carController.BrakeInput = (float)stream.ReceiveNext();
carController.skidding = (bool)stream.ReceiveNext();
}
0
Answers
-
what error?0
-
I am using PUN 2
here is the complete log,
InvalidCastException: Cannot cast from source type to destination type.
Photon.Pun.PhotonStream.Serialize (System.Boolean& myBool) (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:692)
NetworkPlayer.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, PhotonMessageInfo info) (at Assets/Scripts/NetworkPlayer.cs:49)
Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:355)
Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:345)
Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, Int32 networkTime, Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1816)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2189)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2525)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:634)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:550)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1422)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:130)
0 -
Hi @qasim7x,
can you confirm, that you are trying to send and receive the same types? You can also usestream.Count
to get the number of items in the stream andstream.PeekNext()
to see, if the next object is null or something else.
Which Observe Option do you use on the PhotonView component? Reliable Delta Compressed for example only send changes made to the synchronized values. Means that you probably only send one item instead of two.0 -
I am writing the int and bool and then receiving back the int and bool, respectively.
and my observed option is Unreliable on change .0