OnPhotonSerializeView() doesn't work correctly after reconnect (rejoin)

Options
Hi Friends!
We working on unity3d.
The Game works fine.
All game logic calculates Master Client.
Any Client can be MasterClient, if masterClient was disconnected,
My problem apperars after reconnect to room!
The client, who was reconnected, on he's scene, units (mobs, creeps, soldiers) staying on position where they spawned at first time, it is doesn't matter when they spawned (before or after disconnect).
Then, someone spawn new units, they works fine, OnPhotonSerializeView() works correct.
I checked all params on units, all is ok ( in inspector debug mode too).
MasterClient's OnPhotonSerializeView() works,
but client's OnPhotonSerializeView() not calling.
And units, who stuck on wrong position, some time can resume normal activity. о.о
My code:
public class MobSerializationNetwork : Photon.MonoBehaviour {
           void Start() {
               m_MobScript = GetComponent<Mob>();
               m_Transform = transform;
               m_CorrectPlayerPos = m_Transform.position;
               m_MobScript.photonView.ObservedComponents.Clear();
               m_MobScript.photonView.ObservedComponents.Add(this);
               m_MobScript.photonView.synchronization = ViewSynchronization.ReliableDeltaCompressed;
               if (m_MobScript.photonView.RpcMonoBehaviours == null) {
                   RestartSerialization();
               } else if (m_MobScript.photonView.RpcMonoBehaviours.Length == 0 ) {
                   RestartSerialization();
               }
           }
           public void RestartSerialization() {
               m_MobScript.photonView.RefreshRpcMonoBehaviourCache();
           }
           void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
              // Debug.Log("i'm working");
               if (stream.isWriting) {
                   stream.SendNext((short)m_MobScript.lookDirection);
                   stream.SendNext((byte)m_MobScript.animState);
                   stream.SendNext((Vector2)m_Transform.position);
               }
               else {
                   m_MobScript.lookDirection = (short)stream.ReceiveNext();
                   m_MobScript.animState = (AnimState)((byte)stream.ReceiveNext());
                   m_CorrectPlayerPos = (Vector2)stream.ReceiveNext();
                   syncTime = 0f;
                   syncDelay = Time.time - lastSynchronizationTime;
                   lastSynchronizationTime = Time.time;
               }
           }
           void Update() {
               if (!PhotonNetwork.isMasterClient) {
                  syncTime += Time.deltaTime;
                   m_Transform.position = Vector3.Lerp(m_Transform.position, m_CorrectPlayerPos, syncTime / syncDelay);
               }
           }
}
Units spawns by PhotonNetwork.InstantiateSceneObject(...);
Anyone have some idea about this?
I checked all params on units, all is ok ( in inspector debug mode too).
4 days we can't resolve this problem:neutral:
And sorry for my bad English:blush:

Best Answer

Answers

  • Tobias
    Tobias admin
    edited June 2016
    Options
    Instantiation, OnPhotonSerializeView and RPCs will currently break when you rejoin, because so far, the server does not pickup the last state of PhotonViews.

    You need to use Custom Properties and PhotonNetwork.RaiseEvent() to synchronize your game state without relying on PhotonViews, to support ReJoin properly.


    The reason for this is how client (PUN) and the server (pure Photon without Unity components) keep track of the entities that the clients "make up".
  • Tobias
    Options
    That stuff happens. It's good to know you could find it and make progress again :)
  • BigGameCo
    Options
    Tobias wrote: »
    Instantiation, OnPhotonSerializeView and RPCs will currently break when you rejoin, because so far, the server does not pickup the last state of PhotonViews.

    Is this still the case?

    Also can you please explain what you mean by "You need to use Custom Properties and PhotonNetwork.RaiseEvent() to synchronize your game state without relying on PhotonViews, to support ReJoin properly."? The link you posted above is broken.

    Thanks