Modifiers - Vaei/PredictedMovement GitHub Wiki
[!IMPORTANT] Modifiers are robust stackable predicted movement states
Modifiers
Applying and Removing Modifiers
This guide is in the context of Boost, but it is the same for all modifiers
Call Boost()
to apply a Boost and UnBoost()
to remove the Boost. You can call ResetBoost()
to clear all boosts.
[!WARNING] Separate net types are separate data structures, you must ensure you pass the same net type used to add the boost to remove or reset boosts
State-Based Application of Modifiers
If you want to conditionally apply modifiers based on a state instead of relying on input, e.g. which weapon the character has equipped, then this must be done in C++.
Override your character movement component's UpdateCharacterStateBeforeMovement()
and before you call Super
modify the modifier's WantsModifiers
array.
You could update it based on tags on the UAbilitySystemComponent
if you want to use GAS state to determine levels. This is a tested workflow.
Modifier Levels
Modifiers can have multiple levels, defined by gameplay tags. How you choose to represent this will be highly project dependent. Internally, the modifier system maintains an index based array of the tags that you define.
So if our modifier level is 0, then the first level from the array is active. Note: modifier level is UINT8_MAX
(255) if it is not active!
However, you can activate level 0, or any level of the modifier, as many times as you wish, optionally limited by a parameter, e.g. MaxBoosts
When multiple levels are active at the same time, the modifier level method determines how we calculate a resulting level.
Each modifier has an EModifierLevelMethod
parameter with the following options:
- Max
- Min
- Stack
- Average
Max
will simply always take the highest active level and apply it's parameters.
Min
is the same, but the lowest active level.
Stack
will combine all the levels. If you have added Boost.Level1
up to Boost.Level5
and you apply 3x Boost.Level1
, the resulting level will be Boost.Level3
.
Average
will take each active level and average it out. If you have 1x Boost.Level1
and 2x Boost.Level4
applied, the result will be Boost.Level3
.
Net Types
Local Predicted
Similar to Sprint, Crouch, etc. and is typically activated via Input or State that the client controls, or walking into a trigger volume.
Local Predicted + Correction
Same as Local Predicted above, however the server will send a net correction if it disagrees with the client's state, and the client will assume the server's state.
An example use-case is an inventory event that equips a knife that increases our move speed via a Boost. If the client didn't adequately predict the state based on inventory, or fell out of sync, the server can correct that.
Server Initiated
This is something that cannot be predicted, such as receiving damage from the server resulting in a snare or knockback. The server sends it's state as a net correction and the client applies it.
This will result in de-sync, but you can use the included client authority system to mask it so the player doesn't feel it.
Another example could be a player, with a mage-type class, casting a slow fall-type spell on another player.
Adding Your Own Modifiers
[!CAUTION]
single-cmc
includes Boost, Haste, Slow, Snare, SlowFall and this is intended to cover the needs of most projects. Adding modifiers is not a simple process and is only for intermediate or advanced users and is C++ only. If you think of modifiers that would be well-suited to most projects then raise an issue and request it.
Adding your own modifier requires forking or extending the plugin.
From there, identify the closest included modifier and duplicate it throughout both the movement component and character. Don't miss anything or it won't work properly!