Appearance
MotionAttributeSet
MotionAttributeSet is the default GAS AttributeSet for Motion movement and stamina attributes. It can synchronize selected attributes with CharacterMovementComponent.
Requirements
- The
AbilitySystemComponentmust be able to own AttributeSets. - You must initialize the Gameplay Ability System.
- The character must have a standard
UCharacterMovementComponent.
Additional GameplayEffects are not necessary to define the attributes.
Setup Reference
You can add UMotionAttributeSet to the ASC in your character setup. When the ASC does not contain UMotionAttributeSet, a Motion component requests the default set. The server creates the set without an additional action. Motion can also find compatible attributes by name in your AttributeSet.
The constructor sets the default values. To initialize from a DataTable, pass an FAttributeMetaData row table to AbilitySystemComponent::InitStats or K2_InitStats. Rows use names such as MotionAttributeSet.WalkSpeed. Automatic default-set creation calls InitStats with no DataTable. Thus, it uses the constructor defaults.
For a custom ASC setup, you can create UMotionAttributeSet. When PlayerState owns the ASC, create the AttributeSet with PlayerState as its outer. Then, the set can persist across respawn. Use UMotionAbilitySystemHelper::InitializeCharacterAbilitySystem for ASC owner/avatar bindings.
Behavior
When attributes change, the AttributeSet clamps selected values and updates CharacterMovementComponent when applicable. It sends GAS attribute notifications and replicates attributes through OnRep functions.
WalkSpeed synchronizes with MaxWalkSpeed and MaxWalkSpeedCrouched. If the character has MotionCrouchingComponent and is not crouched, crouched speed becomes max(WalkSpeed + CrouchWalkSpeedModifier, 0.0). For other conditions, crouched speed becomes 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. When the ASC is available, it writes the value to the server-owned WalkSpeed base value. Then, it synchronizes CMC with the active 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(): This is an inherited extension point for reactions to GameplayEffect execution. Motion does not override it in this release.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: This is the base walking speed for character movement. With
MotionWalkComponent, the base value starts from profile-appliedBaseWalkSpeedof the component.
JumpVelocity
- Type:
FGameplayAttributeData - Default:
420.0 - Replication:
OnRep_JumpVelocity - Clamping: minimum
0.1 - Auto-sync:
CharacterMovementComponent->JumpZVelocity - Description: This is an optional GAS-driven jump velocity that synchronizes with CMC.
MotionJumpComponentdoes not read it.
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:
MaxStaminahas no clamp. WhenMaxStaminareplicates, Motion decreasesStaminaif 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 active stamina is greater than or equal to the specified 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. For other conditions, it does these actions:
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.
Typical Gameplay Effects
- Sprint speed increase: Add a positive SetByCaller magnitude to
WalkSpeed. Usually, the sprint profile supplies this magnitude. - Crouch speed decrease: Add a negative SetByCaller magnitude to
WalkSpeed. - Walk speed initialization: Set or offset
WalkSpeedfrom profile-appliedBaseWalkSpeedof the component. - Jump velocity change: A project GameplayEffect can add to or override
JumpVelocity. This is separate from the profile-drivenMotionJumpComponentjump 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 each active flag. They also apply the active attribute value to CMC. Movement components in this release set those flags after authoritative speed-effect application or removal on a locally controlled authority instance. They do not use autonomous-client speed prediction.