Hey!
I’m experienced in C++ and programming overall, including gamedev (not multiplayer though), but I’m new to Unreal Engine. I’m making a game in UE4 as a university project and I need to implement online multiplayer (due to university guidelines i need to use TCP, so let’s ignore UDP for now). I do know that UE4 itself has an implementation of online multiplayer and if I understand correctly it uses the replication mechanism (all actors etc. contain properties that can be replicated, meaning they will be synchronised between the server and clients). BUT, I canNOT use that implementation and have to create my own implementation of sockets (done) and a custom protocol (not started yet).
What would be the best approach to achieve custom implementation of server and client like that? How do I make the server aware of each and every actor/property that needs to be replicated? Can i somehow hook into the replication mechanism or do I have to create it from scratch?
Thanks in advance, any advice will be greatly appreciated!
I’m sorry to be the this guy - but if this is something you’ve been instructed to do by a University then this frustrates me beyond all reason.
I don’t know how much help you’ll realistically get with this because virtually anybody developing a multiplayer game in UE4 is using the built-in system unless they’re either a) insane or b) doing something incredibly niche and/or specific. There is no “hook” for replication as such, the whole networking architecture of UE works as a unanimous system, and is heavily integrated with all different parts of the engine.
NB: I’m also not sure I understand why you would have to use TCP. Using TCP is the first thing you learn not to use when it comes to multiplayer game programming.
Well, true and false at the same time. Basically we need to do an UE4 game AND make an online multiplayer game (not necessarily in UE). It doesn’t have to be the same project, but we had to choose between doing 2 games for different purposes or connecting all the features in one. Maybe this was the wrong choice.
Basically we could choose between both UDP and TCP, but the university requirements for the UDP variant are so huge (a lot of additional conditions) that we just wouldn’t have time to implement them all. We chose TCP to make it smaller and - possibly - easier.
Well that’s a shame. I guess I will just need to make some “dirty” code to do the work and just fulfill the requirements.
Thank you for taking your time to reply, I really appreciate the response. Have a nice day!
Ah fair enough, I misinterpreted a bit then - initially it sounded as though you were being told to do something a bit insane.
It’s tricky to give any specific advice though really, the networking system is built on top of UE’s libraries and it’s object system etc, it’s all very intertwined and isn’t something that’s designed to be swapped out and replaced. The protocol UE4 uses is UDP, with it’s own internal system for “reliability” which is far better suited to games in general.
I agree with TheJamsh, for the most part – you either use the existing replication system, or you make something completely different, if you have wildly different needs (and in your case the need seems to be “build the networking code for something multiplayer”, which is wildly different from “use Unreal’s built-in multiplayer networking replication”). Besides, if you hooked into the existing system, you’d only be building your own transport mechanism, rather than the entire thing right?
What I don’t agree with is that you should always use UDP. TCP is perfectly fine for many multiplayer applications, but it is not fine for the way that Unreal’s replication system works, which has been honed over literally over 2 decades, to excel at twitch shooters. While this means it’s also usable and works well for just about any other application, that doesn’t mean that other applications aren’t well served by something completely different.
In my last career – i wish i could go into a lot more detail, but I can’t – I had the task of connecting several different rendering engines (we used Unreal, Unity, a custom Qt system, and a custom HTML system) simultaneously to a remote server, to display various things. Basically, I created a “world server” which was a service that kept track of the state of the “world”, and then you could connect to it via WebSocket from any of the clients, receive the world data from the server, and it would render what it was told to, where it was told to. Clients could also send commands back to the server to request to alter the state of the world.
So, I basically implemented a basic multiplayer system that allowed for entirely different rendering engines to connect to a common server, and all render the same thing.
Unreal side, I did that with a custom WebSocket plugin, which I connected to at game startup, and then just handled all the messages in my GameMode. Basically did the same thing across all 4 clients, just using whatever their version of websocket and sticking code in to parse the incoming messages, and adjust the output in the world was.
So, there’s absolutely nothing preventing you from implementing your own multiplayer, but hopefully you wouldn’t need anything near as complex as what Unreal already provides, otherwise it’s going to be a bit of a problem
You don’t. You can build your own complicated state sync mechanism, but that is most likely far beyond the scope of your task. Simply hooking up your own socket connection to the built-in networking logic of Unreal on the other hand seems to defeat the purpose of the task you are given. What makes more sense is to send a limited amount of data (this is where the custom protocol comes in, you decide how to send that data exactly) and then specifically update certain actors as required to represent this data. Usually clients would send some sort of input that the server processes to simulate the game state and the server would update clients about the resulting game state. For some simple games it is enough to simply forward player input to other players and have them update the world state separately (that’s basically a peer to peer setup).
The complexity of doing this from scratch in Unreal with a custom TCP socket connection isn’t going to be any more or less than making your own networked game without Unreal.