's tips are very helpful.
What I can tell you from experience, that it takes a while to fully understand Unreal’s networking. There are gonna be moments when you’ll pull your hair out and rewrite whole classes just to get it to work correctly. But when you finally master it, it’s amazingly easy and fun to use.
Some pro-tips I can give you are:
Replication and RepNotifies are the two best things in the world. If you use them correctly you’ll barely notice you’re writing networked code.
NetMulticast should be avoided if possible (in most cases it can be, but sometimes it’s necessary. Learn to differentiate it from Replication and understand its use)
Also, you have to understand the difference between Authority, Simulated Proxy and Autonomous Proxy.
Say you’re playing a 1v1 match online:
You’re sitting at home at your computer, you’re connected to the server. You are the Autonomous Proxy, the client.
But what about your opponent? Is he a client? No. Your computer just creates him, since the server tells your computer that he’s in the match as well. He’s simply a replicated actor from the server. Your computer however, still runs his code, still “plays” as him. But your computer plays him as a Simulated Proxy, a “third person”, if you will.
The roles are of course reversed at your opponent’s computer.
But there’s a third computer also “in the match”, which is the server. And the server is the master of everything, and has the role “Authority”.
Try setting up a testing level and use these checks to see which role you have, and make sure you understand it. It’s the first step and it’s imperative you know the differences.
AMyActor::BeginPlay() {
switch (Role) {
case ROLE_Authority:
/* Server * /
break;
case ROLE_AutonomousProxy:
/* Client */
break;
case ROLE_SimulatedProxy:
/* Simulated Client */
break;
default: break;
}
}
Also understand that in this 1v1 match, there are three Worlds (World as in “GetWorld();”)
Your world, the one at your computer. Your opponent’s world. And the server’s world (Although the server doesn’t render any graphics, he totally has a world)
NOTE: This example is for when running a dedicated server. You can also host your own server, which makes you both client and server.