Search code examples
c#unity-game-enginenetworkingnetwork-programmingphoton

After creating a room at the beginning of the match, will the room dissapear after everyone leaves in Photon Unity?


I'm working on a game with Photon in unity. I'm making a system that when the player clicks play, it puts them in a room that fits. If there's no room, it automatically creates a new room, but I'm curious that if everyone leaves the room, will it disappear or does it just stay there?

I'm also worried that if the rooms stay there, the players will play and leave and create more and more rooms.

For example, if there are 1000 rooms created and 1000 players online: it's gonna be a disaster if 1000 players join 1000 rooms then if each room has 1 player, they can't play.

If yes, is there any function to destroy the room after everyone leaves?


Solution

  • By default rooms do that automatically.

    see Room.EmptyRoomTtl

    Room Time To Live. How long a room stays available (and in server-memory), after the last player becomes inactive. After this time, the room gets persisted or destroyed.

    by default this is 0.

    See also RoomOptions which can be passed to the overload of PhotonNetwork.CreateRoom(string, RoomOptions, TypedLobby = null) and there RoomOptions.EmptyRoomTtl

    Time To Live (TTL) for a room when the last player leaves. Keeps room in memory for case a player re-joins soon. In milliseconds