iosswiftgamekitgkmatchmaker

GameKit / GKMatchRequest: timeout or forced start?


I am using GKMatchmakerViewController to have the user auto match with players for my multiplayer game:

        if let matchmakerViewController = GKMatchmakerViewController(matchRequest: request) {
            matchmakerViewController.matchmakerDelegate = self
            
            let rootViewController = UIApplication.shared.windows.first!.rootViewController
            rootViewController?.present(matchmakerViewController, animated: true)
        }

This method of finding a match seems to wait for about 10 minutes if there are no players available. No sane player is going to wait that long for matches.

Therefore I would like to be able to set a timeout so that after n amount of seconds, the match starts anyway even though not all of the slots have been filled. I can then spawn bots or AI players.

Is this not possible with GameKit?

I tried using matchmakerViewController.canStartWithMinimumPlayers = true so it's possible to have the match start even when not all slots have been filled, but the player is then still forced to wait until the minimum amount of players are connected (still max 10 minutes).

I would like to set a timeout (eg. 30-60 seconds). The GKMatchmakerViewController would then fail if there are 0 players, or return with less players than requested.

Alternatively I would like to implement a "forced start", and tell the GKMatchmakerViewController to no longer wait.

Didn't Apple think of this or am I missing something?


Solution

  • It is impossible to force start a match with 0 matches when using GKMatchmakerViewController.

    As an alternative, use GKMatchmaker. This can be canceled with GKMatchmaker.shared().cancel() (eg. after 30 seconds) and then the game logic can simply start a game with 0 players and add bots.