Skip to content

MotionAttributeSet

Default GAS AttributeSet providing movement and stamina attributes with automatic CharacterMovementComponent synchronization.

Requirements

  • MotionPlayerState configured in GameMode
  • Gameplay Ability System (GAS) initialized
  • Character with standard UCharacterMovementComponent
  • No additional Gameplay Effects required - attributes are defined here

Installation

  1. MotionAttributeSet is automatically included with MotionPlayerState
  2. No manual setup required if using MotionPlayerState
  3. For custom setups, add to your AbilitySystemComponent:
    cpp
    AbilitySystemComponent->AddAttributeSetSubobject<UMotionAttributeSet>();
  4. Default values are set automatically on initialization

To override the default values used in the AttributeSet, create a DataTable with Row Type AttributeMetaData.

Functionality

The AttributeSet manages character attributes and automatically syncs them with movement components.

Expandability

FunctionDescriptionUse Case Examples
PostAttributeChange()React to attribute changes• Trigger UI updates
• Apply additional effects
• Handle prediction reconciliation
PreAttributeChange()Validate before changes• Prevent invalid values
• Add change conditions
PostGameplayEffectExecute()React to GE execution• Log attribute changes
• Trigger abilities
GetLifetimeReplicatedProps()Customize replication• Add conditional replication
• Change rep conditions

Gameplay Attributes

Movement Attributes

AttributeTypeDefaultReplicationAuto-SyncDescription
WalkSpeedFGameplayAttributeData600.0OnRep_WalkSpeedCMC->MaxWalkSpeedBase walking speed for character movement
SprintSpeedFGameplayAttributeData300.0OnRep_SprintSpeedNoneSprint speed modifier (additive to WalkSpeed: 600 + 300 = 900 total)
JumpVelocityFGameplayAttributeData420.0OnRep_JumpVelocityCMC->JumpZVelocityJump velocity for character jump mechanics

Stamina System Attributes

AttributeTypeDefaultReplicationClampingDescription
StaminaFGameplayAttributeData5.0OnRep_Stamina0.0 to MaxStaminaCurrent stamina amount for sprint mechanics
MaxStaminaFGameplayAttributeData5.0OnRep_MaxStaminaNoneMaximum stamina capacity
StaminaRegenRateFGameplayAttributeData1.0OnRep_StaminaRegenRateNoneStamina regeneration per second when not sprinting
StaminaDrainRateFGameplayAttributeData1.0OnRep_StaminaDrainRateNoneStamina consumption per second when sprinting

ATTRIBUTE_ACCESSORS Macro

Each attribute automatically gets these accessor functions via the ATTRIBUTE_ACCESSORS macro:

cpp
// For each attribute (using WalkSpeed as example):
static FGameplayAttribute GetWalkSpeedAttribute();     // Get attribute reference
float GetWalkSpeed() const;                           // Get current value
void SetWalkSpeed(float NewValue);                   // Set new value
void InitWalkSpeed(float InitialValue);              // Initialize value

Usage Examples

cpp
// Get current attribute values
float CurrentSpeed = AttributeSet->GetWalkSpeed();
float CurrentStamina = AttributeSet->GetStamina();

// Set attribute values (triggers PostAttributeChange)
AttributeSet->SetWalkSpeed(800.0f);
AttributeSet->SetStamina(3.0f);

// Initialize attributes (typically done once)
AttributeSet->InitWalkSpeed(600.0f);
AttributeSet->InitMaxStamina(10.0f);

// Get attribute references for Gameplay Effects
FGameplayAttribute WalkSpeedAttr = UMotionAttributeSet::GetWalkSpeedAttribute();
FGameplayAttribute StaminaAttr = UMotionAttributeSet::GetStaminaAttribute();

Attribute Access

C++ Access

cpp
// Get attribute value
float CurrentSpeed = AttributeSet->GetWalkSpeed();

// Set attribute value (triggers sync)
AttributeSet->SetWalkSpeed(800.0f);

// Init from data table
AttributeSet->InitWalkSpeed(600.0f);

Blueprint Access

blueprint
Get Walk Speed from Attribute Set
├── Target: Motion Attribute Set
└── Return: Float (Current Walk Speed)

Set Walk Speed on Attribute Set
├── Target: Motion Attribute Set
└── New Value: 800.0

Gameplay Effect Access

Gameplay Effect: GE_Motion_SprintSpeed
├── Modifiers
│   └── Attribute: MotionAttributeSet.WalkSpeed
│       ├── Modifier Op: Add
│       └── Magnitude: 300.0
└── Duration: Infinite

Automatic Synchronization

The AttributeSet automatically syncs with CharacterMovementComponent:

WalkSpeed → MaxWalkSpeed

  • Changes to WalkSpeed attribute update CMC MaxWalkSpeed
  • Happens in PostAttributeChange
  • Works for both server and client

WARNING

The WalkSpeed attribute syncs only to MaxWalkSpeed. The MaxWalkSpeedCrouched property is managed separately by the crouch component and is not controlled by attributes.

This is subject to change.

JumpVelocity → JumpZVelocity

  • Changes to JumpVelocity attribute update CMC JumpZVelocity
  • Instant synchronization
  • Respects network authority

Implementation Detail

The sync to CharacterMovementComponent includes intelligent prediction handling. During client prediction, the system temporarily ignores server updates that would cause rubberbanding, ensuring smooth local gameplay.

Stamina System Integration

When MotionSprintingComponent uses stamina:

  1. Drains Stamina attribute while sprinting
  2. Regenerates Stamina when not sprinting
  3. Clamps between 0 and MaxStamina
  4. Triggers exhaustion at 0

Replication

All attributes are replicated 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 regen rate
  • OnRep_StaminaDrainRate() - Updates drain rate

Attribute Macros

The ATTRIBUTE_ACCESSORS macro provides:

  • GetWalkSpeed() - Get current value
  • SetWalkSpeed() - Set new value
  • InitWalkSpeed() - Initialize value
  • GetWalkSpeedAttribute() - Get attribute reference

Common Gameplay Effects

Sprint Speed Increase:

  • Attribute: WalkSpeed
  • Operation: Add
  • Magnitude: +300 (uses SprintSpeed attribute value)

Crouch Speed Decrease:

  • Attribute: WalkSpeed
  • Operation: Add
  • Magnitude: -200

Jump Boost:

  • Attribute: JumpVelocity
  • Operation: Multiply
  • Magnitude: 1.5

Stamina Drain:

  • Attribute: Stamina
  • Operation: Add
  • Magnitude: -1.0 per second

Performance Notes

  • Attribute changes are optimized for frequent updates
  • CMC synchronization happens only on value change
  • Replication uses reliable RPCs for critical values
  • Clamping prevents invalid states automatically

Client Prediction Handling

The AttributeSet includes advanced prediction logic for smooth multiplayer gameplay:

Local Prediction System

When Motion components (Sprint/Walk) apply speed changes on clients:

  1. Components set bIsLocallyPredicting flag with predicted speed value
  2. PostAttributeChange checks if client is actively predicting
  3. If server update matches prediction (within 1.0 tolerance), prediction state cleared
  4. If mismatch, client skips server update to avoid rubberbanding

Prediction Flow

Motion - Advanced First Person Character Controller