中EN

Gameplay Attributes and Attribute Sets

  • FGameplayAttribute stores float values; stored in Attribute Set registered with ASC; handles clamping, temporary changes, base changes.
  • Current vs base: Jump Height base 100, tired GE 70% → current 70; level up base 110 → current 77.
  • Attributes without an Attribute Set are not recommended (no defined behaviors).
  • Setup: UAttributeSet subclass with FGameplayAttributeData UProperties; store on Actor as const UMyAttributeSet* UPROPERTY; registered automatically when instantiated (constructor or BeginPlay, if GetAbilitySystemComponent valid), or Default Starting Data, or ASC->GetSet<UMyAttributeSet>().
  • An ASC can have multiple Attribute Sets, but each must be a different class.
  • Applying a GE for an attribute the ASC lacks makes the ASC create a matching attribute, but no Attribute Set.
  • Macros: GAMEPLAYATTRIBUTE_PROPERTY_GETTER, _VALUE_GETTER, _VALUE_SETTER, _VALUE_INITTER — best practice.
  • Initialization via Data Table row type "AttributeMetaData" (csv: BaseValue, MinValue, MaxValue, DerivedAttributeInfo, bCanStack; name AttributeSetName.AttributeName, case-sensitive). MinValue/MaxValue have no effect — no built-in clamping.
  • Control access in the Attribute Set (not by extending FGameplayAttributeData): custom getter returns Max(current,0); setter uses ASC->SetNumericAttributeBase so modifiers still work. GetGameplayAttributeValueChangeDelegate(...).AddUObject for change callbacks.
  • PostGameplayEffectExecute override example clamps Health.
  • Replication: ReplicatedUsing=OnRep_Health; OnRep_Health(const FGameplayAttributeData& Old) { GAMEPLAYATTRIBUTE_REPNOTIFY(...) }; DOREPLIFETIME_CONDITION_NOTIFY(UMyAttributeSet, Health, COND_None, REPNOTIFY_Always).

引用这一章的笔记

输入关键词开始搜索

滚轮或双指缩放 · 拖动平移 · 双击放大 / 还原