Photon Animator View

Hello,

I have a tower defense game, and trying to set multiplayer gameplay with Photon.

I have two issues. First; when i instantiate enemies to spawn there is a lag on enemy movement for clients. Using PhotonNetwork.Instantiate, and i am sharing my enemy prefab below.

Second; When i instantiate turrets they are not even syncing animators, just stands still when master client turrets shoots. Using PhotonNetwork.Instantiate same way. Sharing turret prefab below.


Copied these from PunBasics Tutorial, but couldnt figure out what i am missing. Can you please guide me?

Thanks.

Answers

  • there is a lag on enemy movement for clients

    Could this just be the usual lag you have to expect? PUN sends 10 updates per second by default, plus the data makes a roundtrip to the server and to the other clients.

    they are not even syncing animators, just stands still

    Hard to say. Maybe "Unreliable on Change" is not a good setting for turrets, which don't move. Or maybe your animations play via triggers and then you need to make sure they can be synced.

  • Hello Tobias,

    -I dont think about being a usual lag because movement is not smooth. It is like there is a flicker on enemy movement. I tried Smooth Sync Movement script but didnt work at all.

    -I changed synchronization types on photonView but nothing changed. It seems Turrets on client not switching attack parameter, should i change that parameter with RPC? Weird thing same scenario on enemies too, but when they are death. Death parameter changes upon death on clients.

    When i check youtube for similar example, couldnt find a RTS example. Is it better to use RPC's for better results? Because i need to change load of code for that.

    Thanks.

  • Please read the doc page I linked to. There is a section about animation triggers. They are not easy to detect in all cases, due to how Unity updates and "consumes" them.

    I would likely sync the state via IPunObservable implementation and ask a script to sync the state explicitly. It is usually more efficient to send updates this way (at least, when there are multiple state changes on a unit, it makes no sense to send them all via RPC).

    If you send one RPC that has parameters for the complete state / state changes, then .. that's fine, too.

  • Hello Tobias,

    You were right, it was about state changes. I handled with OnPhotonSerializeView as boolean. And I have another question for you. I am updating tower's target enemies and want to update on clients too. I tried to use RPC or Raise Events on EventData, but couldnt set Transform or Game Object because it is not supported those types. How can i set Transform or Game Objects across clients.

    Thank you.

  • The Transform and GameObject can't be used as reference, because those are not synchronized. GameObject is a purely local entity for a client and tied to the engine.

    The PhotonView component is used to reference objects in a networked game. You can send the ViewID (as integer) and PUN also registers the PhotonView class as type to send. You could send the target in OnPhotonSerializeView and RPC or via RaiseEvent. I would possibly just add it in OnPhotonSerializeView, as this is sent anyways and you could send this along with other values "active" or "correct" at the time of sending it.

  • rahadinabak
    edited November 2022

    Hello Tobias,

    OnPhotonSerializeView I am getting errors when sending Transform values. I guess it is not supported also game objects.

    if (stream.IsWriting)
        {
         stream.SendNext(target);
        }
        else if (stream.IsReading)
        {
          target = (Transform)stream.ReceiveNext();
        }
    

    Thanks.

  • Correct. Transforms can not be sent. You can not create one on it's own.

    You send Position, Rotation and Scale (or better: the parts you really need) and apply those.

    Have a look at the PhotonTransformView.