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. When a Motion component initializes against an ASC that does not already contain UMotionAttributeSet, the server creates the default set automatically. Motion can also discover compatible attributes by name on your own AttributeSet.
Default values are set by the constructor. To initialize from a DataTable, pass a table with row type FAttributeMetaData to AbilitySystemComponent::InitStats/K2_InitStats; rows use names such as MotionAttributeSet.WalkSpeed. Motion's automatic default-set creation calls InitStats with no DataTable and therefore uses the constructor defaults.
For custom ASC setup, you can still create UMotionAttributeSet yourself. When the ASC lives on PlayerState, create the AttributeSet with PlayerState as its outer so the set can persist across respawn. Use UMotionAbilitySystemHelper::InitializeCharacterAbilitySystem for ASC owner/avatar bindings.
Behavior
When attributes change, the AttributeSet clamps selected values, updates CharacterMovementComponent where appropriate, fires GAS attribute notifications, and replicates attributes through OnRep functions in multiplayer.
WalkSpeed syncs to both MaxWalkSpeed and MaxWalkSpeedCrouched. When the character is not crouched and has a MotionCrouchingComponent, crouched speed becomes max(WalkSpeed + CrouchWalkSpeedModifier, 0.0); otherwise it is set to WalkSpeed.
When MotionWalkComponent is present, its profile-applied BaseWalkSpeed is the initial source of truth for walking speed. The Walk Component applies that value to CharacterMovementComponent->MaxWalkSpeed, writes it to the server-owned WalkSpeed base value when the ASC is available, and syncs CMC from the current effective WalkSpeed.
JumpVelocity syncs to JumpZVelocity when the attribute changes or replicates. This attribute path is independent of MotionJumpComponent, which derives JumpZVelocity from its assigned jump profile when a jump executes and does not query JumpVelocity.
StaminaRegenRate and StaminaDrainRate replicate as attributes but do not directly update CharacterMovementComponent on their own. Components and GameplayEffects consume them when applying stamina behavior.
Expandability
PreAttributeChange(): implemented by Motion to clamp effective values and sync GameplayEffect-driven movement changes to CMC.PostAttributeChange(): implemented by Motion to clamp and sync selected attribute changes to CMC.PostGameplayEffectExecute(): inherited extension point for reacting to GameplayEffect execution; Motion does not currently override it.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 component's profile-appliedBaseWalkSpeed.
JumpVelocity
- Type:
FGameplayAttributeData - Default:
420.0 - Replication:
OnRep_JumpVelocity - Clamping: minimum
0.1 - Auto-sync:
CharacterMovementComponent->JumpZVelocity - Description: optional GAS-driven jump velocity synchronized to CMC; it is not read by
MotionJumpComponent.
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 for
MaxStaminaitself; whenMaxStaminareplicates, currentStaminais clamped down if it is above the new maximum. - 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.
Blueprint usage
Use Gameplay Effects to change Motion attributes. For common stamina queries, use GetStaminaPercent() and HasEnoughStamina().
text
Gameplay Effect: GE_Motion_SprintSpeed
- Attribute: MotionAttributeSet.WalkSpeed
- Modifier Op: Add
- Magnitude: SetByCaller.Magnitude.SprintSpeed (supplied from the active sprint profile)
- Duration: InfiniteBlueprint Helper Functions
GetStaminaPercent()
Returns Stamina / MaxStamina when MaxStamina is greater than 0.0, otherwise 0.0. The helper does not clamp the ratio itself.
HasEnoughStamina(float RequiredStamina)
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 the character is not treated as sprinting, regeneration is not blocked, and the regeneration effect is configured.Staminaclamps between0andMaxStamina.- Sprint exhaustion triggers when stamina crosses the profile-applied
MotionSprintingComponent::MinStaminaToStopSprintingthreshold, not necessarily at zero.
Replication
All attributes replicate with OnRep functions. Each callback returns early when no owning ASC is available; otherwise:
OnRep_WalkSpeed(): syncsMaxWalkSpeedand the crouched speed rule described above on clients, then fires the GAS rep notification.OnRep_JumpVelocity(): syncsJumpZVelocityon clients, then fires the GAS rep notification.OnRep_Stamina(): fires the GAS rep notification after guarding for an initialized ASC.OnRep_MaxStamina(): fires the GAS rep notification and clamps current stamina if it exceeds the new maximum.OnRep_StaminaRegenRate(): fires the GAS rep notification after guarding for an initialized ASC.OnRep_StaminaDrainRate(): fires the GAS rep notification after guarding for an initialized ASC.
The server-side path uses PostAttributeChange for movement sync. Client OnRep functions skip movement sync on authority because the server has already applied the value.
Common Gameplay Effects
- Sprint speed increase: add a positive SetByCaller magnitude to
WalkSpeed, usually derived from the sprint profile. - Crouch speed decrease: add a negative SetByCaller magnitude to
WalkSpeed. - Walk speed initialization: set or offset
WalkSpeedfrom the component's profile-appliedBaseWalkSpeed. - Jump velocity change: a project GameplayEffect can add to or override
JumpVelocity; this is separate fromMotionJumpComponent's profile-driven jump path. - Stamina drain: add a negative stamina magnitude per period.
- Stamina regeneration: add a positive stamina magnitude per period.
Client Prediction Handling
The AttributeSet has shared reconciliation hooks for sprint, walk, and crouch prediction flags. PostAttributeChange and client OnRep_WalkSpeed clear any active flag and apply the current attribute value to CMC. In the current movement-component implementations, those flags are set after authoritative speed-effect application or removal on a locally controlled authority instance; they are not autonomous-client speed prediction.