108 字
1 分鐘
GAS 入門:ASC 要放在 Pawn 還是 PlayerState?
兩種放法比較
| 放在 Pawn | 放在 PlayerState | |
|---|---|---|
| 角色死亡重生 | Attribute、Effect 跟著 Pawn 消失 | 保留在 PlayerState |
| 適合 | AI 敵人、單機遊戲 | 玩家角色、多人遊戲 |
| 網路更新頻率 | 跟 Pawn 一樣 | 需要調高 PlayerState 的 NetUpdateFrequency |
放在 PlayerState 時的初始化
Owner 是 PlayerState,Avatar 是 Pawn。Server 與 Client 要在不同時機呼叫 InitAbilityActorInfo:
// Server:Controller 擁有 Pawn 時void AMyHeroCharacter::PossessedBy(AController* NewController){ Super::PossessedBy(NewController); InitAbilitySystem();}
// Client:PlayerState 複製下來時void AMyHeroCharacter::OnRep_PlayerState(){ Super::OnRep_PlayerState(); InitAbilitySystem();}
void AMyHeroCharacter::InitAbilitySystem(){ AMyPlayerState* PS = GetPlayerState<AMyPlayerState>(); if (!PS) return;
AbilitySystemComponent = PS->GetAbilitySystemComponent(); AbilitySystemComponent->InitAbilityActorInfo(PS, this);}NOTEASC 的 Replication Mode:玩家角色常用
Mixed,AI 用Minimal。
分享
如果這篇文章對你有幫助,歡迎分享給更多人!
GAS 入門:ASC 要放在 Pawn 還是 PlayerState?
https://spartan117.cc/posts/gas/gas-setup-notes/ 部分資訊可能已經過時