Hi all. I have been working on a simple multiplayer test game. I have managed to sync the animations and movements and all the aspects of the game using Server RPC and the in-built replication system that the Character Controller provided.
I’m very happy with my code in that locally testing 2 clients everything works as expect. So I think I am ready to test it. It is the “Server-client model” and so for now I just want to let the user type in their IP address they want to try to connect with.
A long while ago I did successfully right an online game with Unity. I even extended it to use the Dedicated Master Server model eventually but it was a few years ago and I got A LOT of help with it at the time. Unfortunately I cannot remember even where to start with this stuff.
I read the FAQ and found the section about the ‘Online Subsystem’ but I am not sure if this is a little bit overkill for my small project (I got the feeling the Online Subsystem is for interfacing with Steam API, Facebook etc or making Registrations etc -all this stuff I hope to do at a later date).
Could someone poke me in the right direction please? Just where to start to actually begin Matchmaking or just simply connecting two clients together online?
I can post my code if you wish (or even a zip of the project) but it might not be needed since it is all functioning correctly as I mentioned earlier. I now need to add the Connectivity part.
Thanks for reading my long-winded description of the problem. And thanks for any help.
You’re right the Online Subsystem is a generic interface to the most common online features like presence status, creating/joining a session and matchmaking.
If you just want to connect to your UE server over the internet you first need to setup your router to forward port 7777 (default port) to the PC that is running the Server so the Server can receive incoming connections.
A dedicated server requires you to build the engine from source so I recommend you start with a listen-server. A listen-server is where one of the clients is also the server.
You start the listen-server by first ensuring that the Port Forwarding setup is completed. Then you can start listening for connections by calling the OpenLevel(by Name) node. Expand the node and add listen in the Options field. Now when you call this node you should see something like this in the log IpNetDriver listening on port 7777 which means the listen server is ready for someone else to connect.
The other players will connect by calling the ExecuteConsoleCommand node with the command open 127.0.0.1 (Replace 127.0.0.1 with the actual public IP of the listen-server but you can practice using 127.0.0.1 to connect to yourself using another game instance on the listen-server PC).
Thank you very much. This is plenty of info for me to get started. I haven’t actually managed to “Start” my server yet. But I think I now understand the process well enough to try.
Bare in mind that connecting over IP address doesn’t really work with sessions and will require a dedicated server. That is because sessions are Local Area Network.
For connections over raw IP, you will need to build the engine from source which is tremendously difficult to get an existing project created in the binary version to work especially when plugins are a factor.
It is doable, but I would steer you into looking at a source build earlier in development so as to not run into those issues down the road when you try to build your dedicated server since that is the end game anyway.
It does require a TON of disk space. Almost 200GB just for the engine and then add your project size and everything other program to develop with it can be stressful.
Long story short, if you want to build a game with raw IP connections start with a source build because you will HAVE to have it before you can build your server.
Thanks. I’ve made some nice progress but still not fully functioning. I found a tutorial showing me OnlineSubsystem::CreateServer and FindServer.
The thing is, if I run my game directly from my “Playing Map” with two “Client” preview windows then it all works fine (ie. They both spawn and run properly. Even the crouching and animation blueprints are replicated properly).
But then during the tutorial we made a main menu which had two buttons Start and Join. When I load it from this ‘MainMenu.scene’ I get weird issues. Depending on whether I chose Standalone, Client, Listen etc in the preview window, I only ever get one character spawn. Sometimes even clicking connect in one window will open the other window with a spawned player. My GUESS so far is that it is to do with the C++ logic where I specify ‘0’ zero for the “HostingPlayerNum” parameter of CreateServer. Another issue is that FindServer always returns success=1 but results=0.
I made it into a github repo which I believe works and is quite small. If anyone is able to take a look and help me I would be eternally grateful