Synchronize Variables to MasterClient

Options
Hello i got a Problem with Synchronizing Variables.

My Approach is that the Master Client control the Turns.
Up to 8 Players are going to Play in One Room. After a Turn each Player should Fight Random against another Player. So the System Choose a Home and a Away Player.

For this i need to Grab all Turrets from the Away Player and Place them on the Field of the Home Player.

Each Node has a Variable which Contains the Turret GameObject

GameObjects

But the Variable TurretGameObject remains Empty even if theres a Turret Placed on.

GameObjects

I tried to add a PhotonView on the GameObject, but still empty.
Then i tried to add "IPunObservable"
        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.IsWriting)
            {
                // We own this player: send the others our data
                stream.SendNext(this.turretGameObject);
                stream.SendNext(this.turret);
            }
            else
            {
                // Network player, receive data
                this.turretGameObject = (GameObject)stream.ReceiveNext();
                this.turret = (Turret)stream.ReceiveNext();
            }
        }
But it still is empty.

Someone can give me a Hint what im doing wrong?
Thanks for Help in Advance

Comments

  • develax
    develax ✭✭
    edited July 2019
    Options
    Hi @Delner,
    are you sure that OnPhotonSerializeView is not called?

    Your script that is added to the `Photon View's` observed component must implement the `IPunObservable` interface. It seems that everything is done correctly, therefore, the method should be called. The `else` statement will be called only when data changes. And what about `this.turretGameObject` and `this.turret`? You can't just send a whole game object. Instead, you typically want to send and receive some data from an object such as position vector or health points, not references to the objects. If you want to send other complex data like your custom classes more arrangements should be made, read about Photon serialization.