Members Area

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

The Spaceteam Admiral's Club is a community of friends and fans of the game [Spaceteam]. Anyone can create an account but there are special rewards if you support my future projects by becoming a paying member!

Join the Admiral's Club- Henry (aka Captain Spaceteam)

CaptainsMess first release

I've released the first version of my CaptainsMess networking library for Unity!
CaptainsMess on GitHub:

So far it only supports Wifi but I'm planning to add Bluetooth at some point.

Please use this thread for questions, suggestions, and general discussion about the library.


  • Once a game begins, I'm still able to mess with several buttons that shouldn't be available while a game is active (not ready, cancel, etc). Could you include an example of a simple game starting?

    The simplest game I could think of that would demonstrate a progressing game state is first to three of a random number provided by a button press of each user. (User presses button, number rolled displayed to everyone, once all button's pressed/numbers generated, they are compared, winner gets point or tie awards no points).

    On a different note, if two players are connected, and either cancels, the non-canceled players screen is either "..." for host and "Lobby" for clients. I think this message should be "Disconnected" or otherwise let the user know that they need to give action to continue trying to find a game.

    Thank you for making this open source. Networking has always been my biggest hurdle in game creation.
  • Sure, I will add something to the example project this week. For Spaceteam I'm currently using an Animator state machine for tracking game state but I'm still experimenting with it and for the example I wanted to keep things as simple as possible.
    Same with the "Lobby" text field: I wanted to provide a bare minimum example but it certainly has some issues.
  • Hi @Aki , I just pushed a new version of the CaptainsMess library with a simple dice-rolling game as you suggested. Hope it helps.
    The network and game states are handled a bit better, but they're not perfect yet. And I'm still figuring out how to prevent the NetworkManager from changing scenes as it's connecting.
  • Initial test/attempt-to-break-pass works well. It will be later in the week before I can take a crack at understanding the code. Thank you for being awesome!
  • Just spent the whole day messing with this for my latest project. I had been trying to make my own solution for a local networking game, but your system is already much better than I had. I definitely will continue to use it!
  • @hengineer
    Thank you so much for releasing this. Already hit the ground running with it and it's totally exceeding my expectations.

    One question:
    Is there any way to test a game with multiple players on one device? Separate builds don't seem to work like standard Unity networking. I'm running out of devices to test on.
  • Thanks ConnorB! I'm glad it's useful to someone.
    Unfortunately you can't have multiple players on one device at the moment. It could probably be added since Unity's lobby system does allow multiple players per connection, but I haven't looked into it.
    Feel free to experiment!

    For my own local testing I often run the game on my desktop computer and laptop, which is quicker and easier that testing on real devices.
  • @ConnorB

    For testing on a local device, there are some minor issues but I can get away with it fairly easily by tweaking CaptainsMessNetworkManager

    On line 159:
    bool isMe = (aServer.peerId == peerId);

    I simply add the line following:
    isMe = false;

    This isn't a long term nor great solution, and some issues are caused when trying to auto connect. But for "I want to get 5 instances on the same machine to join together for basic testing" situations, works fine for me.
  • @TobiahZarlez

    Thank you so much. I no longer have to have to use 3 laptops and my phone to test. You are a life saver
  • I'm almost done with my game. Last few steps that I need some help on. How do you end the game and put the players back in the lobby together? Don't need exact code, just need a general idea. The example only has an option to play again. Any help would be greatly appreciated.
  • You can end a game at any time by using CaptainsMess.Cancel() but this will not keep the lobby open. If you want to keep the players connected and potentially start another game then there's a missing piece that I've added in Spaceteam but haven't back-ported to CaptainsMess yet. I'll do that today or tomorrow.
  • Ok, @ConnorB, I updated CaptainsMess library with a new "FinishGame" function. Call this when your game is over so it knows you are back in the lobby. As long as you don't call Cancel() then the players will still be connected and you can return to the lobby screen. You should now be able to start a new game with the same players.
  • Having said that, I now realize that the existing lobby might not accept any new players after the game has finished. So you would have to play with the same players or exit the lobby and start a new game.
    In the next version I'll make sure that the lobby is re-opened after the game is over.
  • Awesome. Thanks again. You don't know how helpful you've been.
  • Hi everybody!
    First of all i want to thanks for sharing this project.
    I'n not too good in network programming, so i want to ask for your help.
    I'm trying to make different GUI for host and client and when host press a button at client must changes something, for example to appear a text.
    Can you give me some advises ?
  • Hi @Homa,
    The example included with the CaptainsMess project has a simple game where each person presses a button and then the game does some calculations and changes some text. It's not great but it's a starting point.

    For the game you're describing I would send a ClientRpc message when the host presses their button and then the client can display the text when they receive it.

    You can learn how to use Unity's High-Level Networking API from the official documentation here:
  • hengineer, thx for advice!
    But, honest, i was working a week with no resultant and yesterday i tried ClientRpc and it worked.
    Thanks one more time for this awesome project!
    Have a nice day.
  • Hi @hengineer
    Can you please tell me if i can use your project for 3D real-time game ? I'm trying to see another player, but with no results :(
  • CaptainsMess only handles the discovery of nearby devices and initial connection so once your players are connected then there are no restrictions on the type of game you can make. You can certainly make a 3D game if you want.
    I recommend following the Unity tutorials for setting up a networked game (without CaptainsMess). Once you have something basic working then you can add CaptainsMess later to make connections easier.
  • edited April 2017
    Hi @hengineer
    I'm trying to make connection using a constant IP, but i can't find where is essential connection code for this.
    Can you please help me?
  • @hengineer
    Sorry, find it in Client script - server.ip
  • Just to be clear, if you already know the IP address you're trying to connect to then CaptainsMess is the wrong library to use. It's only purpose is to search for other devices and connect automatically *without* knowing their IP address ahead of time.

    On the other hand, if you usually don't know the IP and you are trying to handle a special case... then carry on!

    The code that starts the connection once the IP address has been discovered is in CaptainsMessNetworkManager::JoinServer
  • Great work on the CaptainsMess library!!

    I have an issue though. I am running Unity 5.5.1f1
    I host a game with Machine A, and then join with Machine B. When I leave the lobby with Machine B, I get an error on Machine A. I created a youtube video to better explain the issue I am having.

    I also had another question that may be tangentially related. If I join a game (on an Android device) and then I force quit the app, is there a way I can detect that on the host?? When I do it in the CaptainsMess library, it doesn't seem to be able to instantaneously detect it. When running the SpaceTeam game and doing the same test, I notice that it can instantaneously detect it and kick the other players back to the title screen.
  • Yes I see that error too. I don't know exactly what causes it because it happens inside inaccessible Unity networking code but so far it hasn't caused any obvious problems so I've been ignoring it. I would like to fix it at some point.
  • As for the disconnection behaviour when you force quit, I experimented with that a little bit but I couldn't get it to work consistently. You can make it disconnect faster by adjusting the timeouts on the NetworkManager but I found that was too fragile (eg. you won't be able to briefly pause the game and resume if someone accidentally presses the home button and then goes back in).
    The way it works now is a compromise but it could definitely be improved.
  • Ahhh so maybe what I can do is set the timeout to be short when players are in the lobby, and then set it higher when the game starts. Can you point me to where I can adjust the timeout in the CaptainsMessNetworkManager? I looked in there but nothing stood out to me as something that could adjust the timeout. I also looked at the Network Settings in Project Settings but no luck there either.
  • Ok it's been a while since I played with it, but something you can try is to select the CaptainsMessNetworkManager prefab in the Editor (Assets/CaptainsMess/Resources) and change Timeouts -> DisconnectTimeout to something smaller.
    I seem to remember having a hard time changing it at runtime though, so good luck!
Sign In or Register to comment.