Problems with OnPhotonSerializeView

Options
Hi all,

I'm new in photon but I'll try to explain my problem:

We have a mobile app (made in unity for android) that will control a computer game (car race game) through accelerometer and buttons, the buttons are send via RPC's and the accelerometer via OnPhotonSerializeView, the race reach its end and the server disconnect the photon client (the OnDisconnectedFromPhoton is called). The app works perfect the first time (even multiple users) the problem comes when we try to reconnect to another room (another race). The problem is that photon actually joins to a Room, and the RPC's works fine, but the OnPhotonSerializeView is never call again. I noticed something strange, when another cellphone, connected to the same room as the another one, moves the accelerometer the OnPhotonSerializeView of the another cellphone(the one that is on debbuging mode) is called but the stream.isWriting is False.

I will attach my code and my classes of the mobile.

[code2=csharp]public class PhotonControlCommunicator : MonoBehaviour
{

private UIManager uiManager;
private ControlPointManager controlPointManager;


void Start ()
{
uiManager = GameObject.Find("UIManager").GetComponent<UIManager>();
controlPointManager = GameObject.Find("ControlPointManager").GetComponent<ControlPointManager>();
CurrentCarId = 1;//por defecto pongo el 1 pero hay que utilizar prefs para almacenarlo y consultarlo
}


[RPC]
public void OnButtonRemotePressed(byte buttonCode,int PungoId)
{

}

void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting && info.photonView.isMine)
{
//Accelerometer values
stream.SendNext(uiManager.accVector3);

}
else
{

}
}



void OnDestroy()
{
Debug.Log("PhotonControlCommunicator destruído");
}
}[/code2]


This is the class that manage all the photon connections
[code2=csharp]public class PhotonManager : Photon.MonoBehaviour
{

private static string _sRoomName = "";
public UIManager uiManager;
private bool _bFirstTime;

public static void PhotonConnect(string sIp, int iPort, string sAppID, string sGameVersion, string sRoomName)
{
//PhotonNetwork.isMessageQueueRunning = false;
_sRoomName = sRoomName;
PhotonNetwork.Connect(sIp, iPort, sAppID, sGameVersion);
}


void OnJoinedLobby()
{
_bFirstTime = true;
PhotonNetwork.JoinRoom(_sRoomName);
}

void OnJoinedRoom()
{

PhotonNetwork.isMessageQueueRunning = true;
PhotonNetwork.Instantiate("PhotonControlCommunicator", Vector3.zero, Quaternion.identity, 0);
if(uiManager.photonGameControlObject == null){
uiManager.photonGameControlObject = FindObjectOfType(typeof(PhotonControlCommunicator)) as PhotonControlCommunicator;

}
}


void OnPhotonRandomJoinFailed()
{

}


void OnMasterClientSwitched()
{
if(_bFirstTime)
{
_bFirstTime = false;
}else
{
PhotonNetwork.Disconnect();
}

}

void OnPhotonJoinRoomFailed()
{
PhotonNetwork.Disconnect();
}

void OnDisconnectedFromPhoton()
{
//Jump to the register code screen
}

}[/code2]

Im doing something wrong??? What I should do the second time that I reconnect? Is a problem from the server side (game) or the client side(mobile app)?

Any help will be very helpful!

Thanks in advance

Comments

  • Tobias
    Options
    I guess your OnPhotonSerializeView() is not complete. Else, it means you write updates (and they get sent) but you never read and apply them on remote clients.

    I can only guess what goes wrong currently, as the code is only part of the problem (maybe your setup in scene is causing this).
    My best bet is now:

    [code2=csharp]if(uiManager.photonGameControlObject == null){[/code2]

    This will not replace the control object you use if you join the room the second time.
    Better use the GameObject that's returned by Instantiate().