JoinRoom OnJoinRoom Instantiate MessageBuffer, etc.

carmine
carmine ✭✭
Hello,
I have the following

Menu "scene" which lists all the games in progress.
Game "scene" where the action takes place.

When a user Join's a room (from the main menu) they (sometimes) get the PhotonNetwork.Instantiate's too early and they are added to the Menu Scene (before getting to the game scene).

I've tried to use the isMessageBuffer = false thing, however, I need to know when "OnJoinRoom" happened so I can move the player into the room.

Can I send the PhotonNetwork.Instantiates and RPC's in another group or something or somehow just block those but keep all the "OnWhatever" functions happening so I can check for errors.

Or am I going about this entirely wrong?

Thanks!

Comments

  • We're doing the exact same thing and fixed it, by implementing a buffer for instantiates and RPCs received before we're done loading all required scenes. We then execute all buffered instantiates and RPCs, when we're ready to do so.

    You can fairly easily snatch all incoming RPCs and Instantiates in the NetworkingPeer class.
  • JakobOerum wrote:
    We're doing the exact same thing and fixed it, by implementing a buffer for instantiates and RPCs received before we're done loading all required scenes. We then execute all buffered instantiates and RPCs, when we're ready to do so.

    You can fairly easily snatch all incoming RPCs and Instantiates in the NetworkingPeer class.

    Did you alter their files? Because if you do, whenever they release a new one it's going to wipe out your work :(
  • Yep, but we've got all our alterations marked up by regions, so it takes about 5 minutes to transfer our code to new PUN versions.
  • I've tried to use the isMessageBuffer = false thing, however, I need to know when "OnJoinRoom" happened so I can move the player into the room.

    Can I send the PhotonNetwork.Instantiates and RPC's in another group or something or somehow just block those but keep all the "OnWhatever" functions happening so I can check for errors.

    This is a new requirement for us.
    You can't load and switch scenes and then re-enable isMessageQueueRunning?

    Can you describe the usecase? Maybe we can support it easily.
  • Tobias wrote:
    I've tried to use the isMessageBuffer = false thing, however, I need to know when "OnJoinRoom" happened so I can move the player into the room.

    Can I send the PhotonNetwork.Instantiates and RPC's in another group or something or somehow just block those but keep all the "OnWhatever" functions happening so I can check for errors.

    This is a new requirement for us.
    You can't load and switch scenes and then re-enable isMessageQueueRunning?

    Can you describe the usecase? Maybe we can support it easily.

    Tobias:

    Player1 is in the lobby. Sees no rooms in the list so creates one and is now waiting in a Scene called "PreGameChatSetup"

    Player2 enters the lobby. Sees a room and clicks "join" and now he is in the room and in the scene called "PreGameChatSetup"

    Player1 [master] and Player2 are both in the same room and scene. Player1 picks the map, gametype, his spaceship color, etc. Things area great and the players decide to start the game.

    Player1 hit's a button [Start Game] which triggers an RPC or Event etc. to let players know it's time to switch to the actual Game Scene, and then Player1 switches Scene to "TheActualGameScene"

    Player2 receives the message to move to the next Scene.

    BUT... Player1's computer is pretty darn fast and ended up in the next scene and sent PhotonNetwork.Instantiate

    Player2 being a slight second behind ends up getting those "Instantiate" messages and attaching them to "PreGameChatSetup" and then a split second later switches to "TheActualGameScene" only to find no one there.
  • do you correctly make use of setReceiveEnabled / setSendingEnabled to prevent exactly this kind of behavior, communication into the wrong scene?

    The Untiy Networking Examples that come with unity show pretty well on how to work with scene switches and prevent 'message fuckups' like the one described here :)
  • dreamora wrote:
    do you correctly make use of setReceiveEnabled / setSendingEnabled to prevent exactly this kind of behavior, communication into the wrong scene?

    The Untiy Networking Examples that come with unity show pretty well on how to work with scene switches and prevent 'message fuckups' like the one described here :)

    I don't know how to use those functions. There really is not enough PhotonNetwork documentation and I'm guessing what things do half the time and end up looking at their code.

    Are those Unity functions or PUN?

    -Carmine
  • Those are functions in both.
    PUNs target is to replicate Unity Networking, as such you can widely rely on the Unity Networking and in this case especially also on the Unity Networking Example on the Resources - Example Projects page of Unity 3D itself to see how they are used etc (I would generally highly recommend to work with it and understand it, it does many crucial things you just have to get a hang on and understand if you are new to networking)