Thursday, April 18, 2013

Multiplayer, multiprayer

Over the weekend, I finally got the time to delve into the multiplayer functionalities of the Unreal Engine from chapter 8 of my book. I was happy to discover that the general way of things is kind of similar to Unity's way, where server and client code are shared, but clearer in a way; instead of RPC calls, just add the keyword 'client' or 'server' in the function prototype and you're done, every call to it will be sent over the network.

For the variables it's even simpler; instead of having your network view tracking some component, you can just add the variables you want replicated in the 'replication' block and have them being automatically replicated under some conditions. Things get more complicated from there, but it's overall pretty logical.

It all looks nice and easy, but setting up the multiplayer was a bit of a pain for a first time user. Of course, there was the regular mistake of forgetting to call the parent class' version of functions in the reeimplementation (in this case, PostBeginPlay(), which is a pretty big deal since the server crashes at that point), which is still as frustrating as the first time ("How could I have been so dumb!"). Once that was done, my next 4 hours were dedicated to dig in the Unreal API and find out why my weapon wasn't firing. As it turns out, a function I had copied from the PhysicsGun class was not necessarily meant to be taken in a multiplayer setting, at least not the way I was doing it. Just changing its name (StartFire to ServerStartFire) did the trick.

Of course, after doing all this it looks *only* like what it did when it was single player. Which means there's no video this time. Still, I'm really happy. The biggest achievements are not necessarily the most visible ones.

No comments:

Post a Comment