OnPhotonSerializeView() doesn't work correctly after reconnect (rejoin)
Options
nipercop
✭
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:
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
And sorry for my bad English
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
And sorry for my bad English
0
Best Answer
-
Thank you Tobias for reply!
We solved a problem!
It was our fail, when someone spawns unit, after that we adding a component MobSerializtionNetwork.cs!
Our careless eyes missed it, all units prefabs must have Serialization component by default!
So shamefully5
Answers
-
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".0 -
Thank you Tobias for reply!
We solved a problem!
It was our fail, when someone spawns unit, after that we adding a component MobSerializtionNetwork.cs!
Our careless eyes missed it, all units prefabs must have Serialization component by default!
So shamefully5 -
That stuff happens. It's good to know you could find it and make progress again0
-
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
0