Ownership of objects

Options
Hi guys,

I am new to Photon and currently in the progress of adding a 1vs1 Multiplayer to my RTS game (Unity).

I am switching from a different Networking Option (Pubnub) so this is why the following setup might be weird to you:

I have a gameplaycursor which shows where the current player just clicked. Imagine it a bit llike a mousecursor or more fitting: a selected Cell in excel.

So Player 1 has two (already instatiated) objects:
OwnCursor and
EnemyCursor.

Player 2 has the same thing.

Now whenever player2 clicks somewhere, the position of OwnCursor (of player 2) is updated AND the position of ENEMYCURSOR (of player 1 !) should be updated too.


I know, the concept of Photon is normally that you instantiate gameobjects and with Photonview and serializedview you send or receive data depending if you are the owner or not.

But since i have a lot of these objects wich are already present in a scene and not beeing instatiated.. how do I deal with them?

Thanks!


Comments

  • Hi @keimax,

    But since i have a lot of these objects wich are already present in a scene and not beeing instatiated.. how do I deal with them?


    the definitely easier way would be to instantiate those objects (one per player) at runtime. If that is not possible you need to set them up correctly before. Therefore both objects need an attached PhotonView component. With this component they are at least owned and controlled by the MasterClient when inside a room. To see how the second client can become the owner of one of those objects I would recommend you taking a look at and reading through the Ownership Transfer guide. When you have done and successfully implemented that you can continue with the following:

    Now whenever player2 clicks somewhere, the position of OwnCursor (of player 2) is updated AND the position of ENEMYCURSOR (of player 1 !) should be updated too.


    This sounds like an ideal use case for RPCs. Whenever one of the players click anywhere, they can use a RPC to notify the other client about the click. To see how RPCs work I would recommend you taking a look at the RPCs and RaiseEvent documentation page.

    Again: instantiating both objects (one per player) at runtime would be much easier because the entire step about Ownership Transfer would drop out and you only would have to deal with the RPCs.
  • keimax
    Options
    Thanks @Christian_Simon

    I will try RPC calls as a test. For most other objects I will follow your advice and instantiate as much as i can at runtime.

    Cheers,
    keimax