How to Properly modify the CharacterMovementComponent for Networked Games

Hello Everybody,

So I am reading this articleand I am stuck on the implementation of “Approach 4: CharacterMovementComponent Ability Implementation” at the very bottom of the page. I understand the first bit where you create a class that inherits from the UCharacterMovementComponent so you can make modifications. Right after that it says to “override AllocateNewMove()”. The problem is that AllocateNewMove isn’t in UCharacterMovementComponent, it is in the FNetworkPredictionData_Client_Character class. So am I supposed to create a parent class of FNetworkPredictionData_Client_Character and then override AllocateNewMove.

Essentially, could someone walk me through the steps illustrated in the “Approach 4: CharacterMovementComponent Ability Implementation” method?

Could you also let me know your preferred way to do networked character movement?

Character movement is a big part of the project I am working on and I want to do it right.

Thank you for you time,
Farshooter

I will try to help you, but that’s not an easy part.

You have to create a new class that will override some FSavedMove function
1 - uint8 FSavedMove_YourProjectCharacter::GetCompressedFlags() const
Here you will set the flag in a Int8 so your bool data will be transfered to the server from the client. FLAG_JumpPressed && FLAG_WantsToCrouch are already used. So you have 6 bool flag that you can use. 2 are reserved by Epic but not used and FLAG_Custom_0 to FLAG_Custom_2 that are available for you.

void FSavedMove_YourProjectCharacter::Clear()
Here you are reseting all the value that you set in GetCompressedFlags

void FSavedMove_YourProjectCharacter::SetMoveFor(ACharacter* Character, float InDeltaTime, FVector const& NewAccel, class FNetworkPredictionData_Client_Character & ClientData)
Here you will “save” the data that you want inside Variable that are host in FSavedMove. Those value will be used in GetCompressedFlags() to set the flag.
Ex: Create a bool bSavedMyAbility, set it to true when you ability is True. And use bSavedMyAbility inside GetCOmpressedFlags to set the output Int8 Result.

2- void UYourProjectCharacterMovement::UpdateFromCompressedFlags(uint8 Flags)
Here you will read the flag that you set inside the GetCompressedFlags (it is called on the server side)

I hope this will help.

In the source code, you need to track how the Crouch is done and you will find all the steps I mentionned.
Last, if you want the abilities to be seen on other clients, you will to set Rep variable on the character and manage them properly. (again check the RepIsCrouched).

good luck, this is a bit tricky at the beginning, but once you have all the steps in mind, it becomes fluent.

Thank you Elvince for the detailed answer. I will definitely be studying and digesting this information.

I do have one question. Would you recommend this method for all character movement? For instance if you wanted a networked character to sprint, jump, fly, etc., should you use the same method illustrated above or should you take a different approach? I am just curious as to whether or not I should repeat the methods above for all of my character’s movement.

I don’t have enough experience to say what’s the good way to do things.

I think the best answer will be “it depands” :smiley:
SavedMove is send very often so you can use it to define stuff that may change often. You are limited to an int8 - means 8 differnt bits. Sometime you will be able to combine bit if the abilities are exclusives, so you can save some bit.
Otherwise, RPC is fine. :stuck_out_tongue:

Make a list of your needs, check what can fit within this method and choose what do to in the 8 bits are not enough.