Hoverbike Multiplayer Development Log 1
Hello! I'm Ramanand aka Ram one of the programmers in Unforgiven and due to the massive request to add replication / multiplayer to our Hoverbike System we at Unforgiven have decided that is time to do it . This is something I've been wanting to do since last year but didn't have the time because of university related stuff but now that I have graduated I find myself with more time in my hands.
This series of articles will be focused in the addition of multiplayer to the Hoverbike System you can find here in the Unreal Marketplace. It’s not a tutorial because I’m not an expert in replication in Unreal Engine (yet) but is a log of the steps I did to make the replication work for the Hoverbike. I'll try to show most of the things I did that worked and do my best explaining them but if something is not clear you can ask me in the comment section.
As learning material I used the Unreal Engine documentation found here and this Unreal engine stream that you can watch here.
Week 1: Testing what works and what doesn’t
My first step to tackle this project is to check how much does the hoverbike system breaks when I try to use it for multiplayer out of the box. First set up the number of players to 2 and play around the level to check which problems arise. The player movement is controlled by the Character Movement Component so we don’t have to worry about that.
Initial problems detected after testing:
- Client can’t ride correctly the hoverbike
- Animations are not replicated
- UI behaves incorrectly
- The destruction of the hoverbike because of the damage done to it cause the player mesh to disappear
This test was done in 10 minutes so there is a high probability that I missed something. Don’t worry though because the development is iterative so test will be done exhaustively in order to ensure the best quality we can. I’m doing things this way because the time I give to this project is around 2 hours a day so I rather see results quickly and polish them gradually.
Let’s start by addressing the most important issue “Client can’t ride correctly the hoverbike” which means that the client isn’t telling the server that is riding the bike.
Mount and Dismount
To solve this we have to open the ‘BP_RiderComponent’ and check the ‘Component Replicates’ checkbox under the ’Class defaults’
As a little background, let me explain that to for a pawn/character to use the hoverbike you just have to add the ‘BP_RiderComponent’ and set up some inputs and that’s it. So this actor component plays a large role for the hoverbike to work.
Next we have to edit the ‘BP_MyCustomRider’ to use replicated events (also called RPCs in c++). Following Epic’s standards I created a custom event called ‘ServerMount’ that Runs on the server and is Reliable. I used Run on Server because the possess node needed to mount the hover bike only runs on the server and I checked Reliable because we always want this to happen, otherwise the engine may skip this if there is heavy load on the network.
After this we have to call the ‘ServerMount’ when the input is pressed. So we replace the current mount function to our replicated one.
Our ‘Bp_MyCustomRider’ should look like this after applying the same process
For the dismount, we need to edit the BP_Hoverbike because its there where the event is called. We create another reliable replicated event that calls the dismount in our rider component.
Now we need to fix little things like the bike being able to be mounted by more than one player now that we have replication in the project.
And that would be it for this week, next time I'll check the problems the animations give us and some movement problems I encountered along the way.