Get data from master client.

Hello, What way I can get data from host? I need get spawn position.

I see it like this:
Request to Master Client and get callback from he with Vector2.
But better way without RPC. Can I do it with RaiseEvents?


  • Hi @RandomMan,

    You can do it using RaiseEvent yes.
    You should use a special event code for the event request (to MasterClient) and the event response (from MasterClient).
    You can set the event target as raiseEventOptions.Receivers = ReceiverGroup.MasterClient or using raiseEventOptions.TargetActors = new int[1]{masterClientActorNr}.
    Then from the MasterClient use OnEvent to receive, process and send a response as an event. You can get the sender actorNr like this int actorNr = (int)eventData[ParameterCode.ActorNr];.
  • RandomManRandomMan
    edited June 2017
  • RandomManRandomMan
    edited June 2017
    Okay, it works, but I found a bug. After leave room and joiun again it create me 4 tanks! and every join 4 tanks more, why is it happens?
    Check my code please!
  • Really strange problem, it just MUST work but it is not!
  • If Master Client disconnects it will be replaced by the actor with the next actor number if any.
    When actors leave their instantiated GameObjects should be cleaned up by default.
    What happens when Master Client sends event 0 to himself?
    You should be able to track this down using useful logs.
  • But I tested it only with 1 player and after leaving room got close
  • Increase RoomOptions.EmptyRoomTTL (max 300000) and RoomOptions.PlayerTTL.
  • @JohnTube maybe you don't understand me? I don't need keeping empty room long. I need autoclose it fast, I mean after room closed and I create again I got this event bug. Maybe in Unity Client keep some old info about previous events and it get 2x events bug?
  • As I told you if you are instantiating tanks the PUN way they should be deleted when actor leaves and nothing should be there if the room is closed!
    You should ask yourself why tanks are still there when room is closed or when player has left.
  • No tanks deleted! I checked it... All deleted already. The bug is event calling twice... I checked it by Debug.Log. I could fix it but by very bad way(just make integer and call event function only 1 time and if more than one time it will return) but it very bad way I think because events still will sending between player-host and eat no-need traffic. Just why they sending twice?
  • Maybe events keep after leaving room in Client locally or something? and then they called multiple times(
  • Please log the RaiseEvent calls of same event (add Debug.Log one line before or after with enough details to ID the event: e.g. sender + eventcode + target) then copy paste the logs of the duplicate calls with full stacktrace.
  • RandomManRandomMan
    edited June 2017
    Omg, I fixed that! the mitsake was that PhotonNetwork.OnEventCall+=OnEvent was calling every new join to Room and get 2x.4x.8x etc calling OnEvent! I just in OnLeaveRoom wrote PhotonNetwork.OnEventCall-=OnEvent.

    Okay, my question is finally solved!
  • Hi everyone,

    I am also facing some kind of problem for PhotonNetwork.OnEventCall....

    when client's disconnected due to network loss and reconnects then this method is called after reconnect = >
    public void OnEvent (byte eventCode, object content, int senderId)

Sign In or Register to comment.