Callback for PhotonNetwork.Instantiate?

Options
waxx
waxx
Hey everyone.
I'm looking for a tool or maybe just a suggestion on how to approach this little problem. Here's the deal:
Each client after successful connection performs PhotonNetwork.Instantiate() to create player prefab of whom he wants to be an owner. Now the client that is server performs all the logic and he needs to 'register' the client in the session and provide him player ID and what not and then send it back.

I thought of simply sending an RPC from client to server that a new player is on board, but I can't pass a reference obviously to particular player gameobject, so how will I know which one is it? How can I solve this?

Thanks for your time ^^

Comments

  • vadim
    Options
    Hi,

    You do not need reference to the object if you call RPC for PhotonView of that object. On other clients, RPC will be called for instances of that script and they can register themselves.
    Also if you need to handle only creation then just implement OnPhotonInstantiate handler which is called when instance created.
    Now the client that is server performs all the logic and he needs to 'register' the client
    If you really mean 'registering client' then you do not need this. PhotonNetwork.playerList is list of all players (clients) with Photon player id assigned.
  • Tobias
    Options
    You can put one GameObject in the scene and keep it around. This could be used by every client to call RPCs that the Master Client should execute.
    The Master Client can also just network instantiate scene GameObjects per new player. The Master Client has control (sends updates) but if it leaves, another client will become master and take over.
    Each player can indirectly control it's GameObject by calling RPCs on it. The Master Client must evaluate those and modify the GO accordingly.

    Be aware that this introduces some extra lag.
  • waxx
    Options
    Thanks guys, in the end I chose initializationData to transfer my internal ids and I assign it in Awake().

    Another quick question though - when exactly are gameobjects instantiated for new clients? I've got some game init functionality in the onjoinedroom but it seems to be happening before all the objects are initialized on launch. Is there any way to control this?
  • Tobias
    Options
    "[...] when exactly are gameobjects instantiated for new clients? [...]"

    You mean when joining?
    You can disable the message queue while loading / initializing. This might help: PhotonNetworking.isMessageQueueRunning = false. Set it to true when you're ready.