Non master client can't see networked gameObjects

Options
Hello,
I am making a 1 v 1 RTS game, my problem is that the non master client can only see objects instantiated by him only, not the ones instantiated by the master client, but on the other hand the master client can see the objects instantiated by him and the other player, the instantiated gameObjects are the same, they have a photonview synchronizing transform,rigidbiody and the animator,

the coroutine called to instantiate the units
IEnumerator Instantiator()
{
MyPlayerManager GM = cam.GetComponent();

GameObject BaseTower = GM.BaseTower;
TowerSelection TS = BaseTower.GetComponent();

int randUnit = Random.Range(0, units.Length);
GameObject Unit = units[randUnit];
Vector3 pos = new Vector3(BaseTower.transform.position.x, -0.06f, BaseTower.transform.position.z);
while (TS.NrOfUnits > 0)
{

PhotonNetwork.Instantiate(Unit.name, pos, Quaternion.identity,0);
TS.NrOfUnits--;
yield return new WaitForSeconds(0.08f);
}

}
and fot the units(instantiated gameobject) script, for the networking part I have this


public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(_rb.position);
stream.SendNext(_rb.rotation);
stream.SendNext(_rb.velocity);
}
else
{
_networkPosition = (Vector3)stream.ReceiveNext();
_networkRotation = (Quaternion)stream.ReceiveNext();
_rb.velocity = (Vector3)stream.ReceiveNext();

float lag = Mathf.Abs((float)(PhotonNetwork.time - info.timestamp));
_networkPosition += (_rb.velocity * lag);
}
}
public void FixedUpdate()
{
if (!photonView.isMine)
{
_rb.position = Vector3.MoveTowards(_rb.position, _networkPosition, Time.fixedDeltaTime);
_rb.rotation = Quaternion.RotateTowards(_rb.rotation, _networkRotation, Time.fixedDeltaTime * 100.0f);
}
}


Comments

  • Hi @Mehdi22,

    is there any scene loading after the non-MasterClient joins the room? In this case, the instantiated objects of the MasterClient might get destroyed on the non-MasterClient. To prevent this, you can try marking the objects as DontDestroyOnLoad.