Appearance
MotionAttributeSet
MotionAttributeSet is the default GAS AttributeSet for Motion movement and stamina attributes. It can synchronize selected attributes with CharacterMovementComponent.
Requirements
- An
AbilitySystemComponentthat can own AttributeSets - Gameplay Ability System initialized
- Character with standard
UCharacterMovementComponent
No additional GameplayEffects are required just to define the attributes.
Setup Reference
UMotionAttributeSet can be added to any ASC used by your character setup. Motion can also discover compatible attributes by name on a project-specific AttributeSet.
Default values are set on initialization. To override default values, use a DataTable with row type AttributeMetaData.
Behavior
When attributes change, the AttributeSet clamps values, updates CharacterMovementComponent where appropriate, fires change delegates, and replicates attributes through OnRep functions in multiplayer.
WalkSpeed syncs to both MaxWalkSpeed and MaxWalkSpeedCrouched. The crouched speed is updated proportionally so its ratio to walk speed is preserved.
When MotionWalkComponent is present, the assigned walk profile's BaseWalkSpeed is the initial source of truth for walking speed. The Walk Component applies that value to CharacterMovementComponent->MaxWalkSpeed, writes it to the authoritative WalkSpeed base value when the ASC is available, and syncs CMC from the current effective WalkSpeed. Configure base walking speed on the walk profile instead of editing the CMC walk speed independently.
JumpVelocity syncs to JumpZVelocity.
Expandability
PostAttributeChange(): implemented by Motion to sync selected attributes to CMC.PreAttributeChange(): inherited extension point for validation before changes.PostGameplayEffectExecute(): inherited extension point for reacting to GameplayEffect execution.GetLifetimeReplicatedProps(): implemented by Motion so all Motion attributes replicate.
Gameplay Attributes
WalkSpeed
- Type:
FGameplayAttributeData - Default:
600.0 - Replication:
OnRep_WalkSpeed - Clamping: minimum
0.0 - Auto-sync:
CharacterMovementComponent->MaxWalkSpeed - Description: base walking speed for character movement. With
MotionWalkComponent, the base value starts from the assigned walk profile'sBaseWalkSpeed.
SprintSpeed
- Type:
FGameplayAttributeData - Default:
300.0 - Replication:
OnRep_SprintSpeed - Clamping: minimum
0.0 - Auto-sync: none
- Description: additive sprint speed modifier.
JumpVelocity
- Type:
FGameplayAttributeData - Default:
420.0 - Replication:
OnRep_JumpVelocity - Clamping: minimum
0.1 - Auto-sync:
CharacterMovementComponent->JumpZVelocity - Description: jump velocity for character jump mechanics.
Stamina
- Type:
FGameplayAttributeData - Default:
5.0 - Replication:
OnRep_Stamina - Clamping:
0.0toMaxStamina - Description: current stamina amount for sprint mechanics.
MaxStamina
- Type:
FGameplayAttributeData - Default:
5.0 - Replication:
OnRep_MaxStamina - Clamping: none
- Description: maximum stamina capacity.
StaminaRegenRate
- Type:
FGameplayAttributeData - Default:
1.0 - Replication:
OnRep_StaminaRegenRate - Clamping: none
- Description: stamina regenerated per second when not sprinting.
StaminaDrainRate
- Type:
FGameplayAttributeData - Default:
1.0 - Replication:
OnRep_StaminaDrainRate - Clamping: none
- Description: stamina consumed per second when sprinting.
Accessors
Each attribute gets accessor functions through the ATTRIBUTE_ACCESSORS macro.
For WalkSpeed, the generated functions are:
cpp
static FGameplayAttribute GetWalkSpeedAttribute();
float GetWalkSpeed() const;
void SetWalkSpeed(float NewValue);
void InitWalkSpeed(float InitialValue);C++ Access
The generated accessors are native C++ helpers on the AttributeSet:
cpp
float CurrentSpeed = AttributeSet->GetWalkSpeed();
AttributeSet->SetWalkSpeed(800.0f);
AttributeSet->SetStamina(3.0f);
AttributeSet->InitWalkSpeed(600.0f);
AttributeSet->InitMaxStamina(10.0f);
FGameplayAttribute WalkSpeedAttr = UMotionAttributeSet::GetWalkSpeedAttribute();
FGameplayAttribute StaminaAttr = UMotionAttributeSet::GetStaminaAttribute();Blueprint Access
text
Get Walk Speed from Attribute Set
- Target: Motion Attribute Set
- Return: Float
Set Walk Speed on Attribute Set
- Target: Motion Attribute Set
- New Value: 800.0Gameplay Effect Access
text
Gameplay Effect: GE_Motion_SprintSpeed
- Attribute: MotionAttributeSet.WalkSpeed
- Modifier Op: Add
- Magnitude: 300.0
- Duration: InfiniteBlueprint Helper Functions
GetStaminaPercent()
Returns current stamina as a normalized 0.0 to 1.0 value. Use it for UI stamina bars.
HasEnoughStamina(float Required)
Returns true when current stamina is greater than or equal to the required amount. Use it for ability cost checks.
Stamina System Integration
When MotionSprintingComponent uses stamina:
Staminadrains while sprinting.Staminaregenerates when not sprinting.Staminaclamps between0andMaxStamina.- Exhaustion triggers at
0.
Replication
All attributes replicate with OnRep functions:
OnRep_WalkSpeed(): syncs walk speed on clients.OnRep_SprintSpeed(): updates sprint speed.OnRep_JumpVelocity(): syncs jump velocity.OnRep_Stamina(): updates stamina display.OnRep_MaxStamina(): updates stamina maximum.OnRep_StaminaRegenRate(): updates regeneration rate.OnRep_StaminaDrainRate(): updates drain rate.
Common Gameplay Effects
- Sprint speed increase: add
+300toWalkSpeed, usually fromSprintSpeed. - Crouch speed decrease: add
-200toWalkSpeed. - Jump boost: multiply
JumpVelocity, for example by1.5. - Stamina drain: add a negative stamina magnitude per second.
Performance Notes
- Attribute changes are optimized for frequent updates.
- CMC synchronization happens only when values change.
- Replication uses critical replicated attributes.
- Clamping prevents invalid states automatically.
Client Prediction Handling
When Motion components apply predicted speed changes on clients:
- The component sets
bIsLocallyPredictingwith the predicted speed. PostAttributeChangechecks whether the client is predicting.- If the server value matches within
1.0, prediction is confirmed and cleared. - If values differ, the server correction is logged and applied.
The server value is always applied as the authoritative result.