1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AttributeSetクラスで他クラスのコンポーネントを連動する。

1
Posted at

C++もGamePlayAbilitySystemも初心者なので自分用のメモ。
自分、敵、味方など複数のキャラクターでHP等の汎用ステータスを作るならステータスはActorComponentクラスで作成してエディタ内でいじれたほうがゲームバランスの検証がしやすいと思うので、AttributeSetとステータス系のComponentを併用できないか考えてみました。
a.png

AbilitySystemComponentについて

https://okawari-hakumai.hatenablog.com/entry/2018/07/22/165242 (おかわりはくまいのアンリアルなメモ)
https://wvigler.hatenablog.com/entry/2021/05/10/095459 (第15回ぷちコン「たぬ吉の大冒険」振り返りその1)
これについては優秀な記事がたくさんありますので導入は省きます。上記の記事をご参照ください。

コンポーネントを追加する

今回はStatusComponentというアクターコンポーネントを作成しました。これを実装したいクラスへ追加します。このクラスにUAbilitySystemComponentクラスとUAttributeSetクラスも追加しています。
CharacterBase.h
aa.png
CharacterBase.cpp
aaa.png

Attributeのステータスを初期化する

AttributeSetクラスで実装したEnergyという変数を、コンポーネントの変数でSetする。
aaaa.png
これでAttributeの値=コンポーネントの値になりました。

AttributeSetクラスで他クラスのコンポーネントを参照する

自作したAttributeSetクラスに自作コンポーネントであるStatusComponent.hをincludeします。
PostGameplayEffectExecuteの定義の中でコンポーネントの変数も変更されるようにします。
aaaaa.png
これでGamePlayEffectでAttributeSetのEnergyを変化させると、CharacterBaseクラスに追加されているStatusComponentのEnergy変数も同時に変化するようになりました。

自分用のメモなので、もしかしたら間違っているかもしれません。もし詳しい方がいらっしゃったら回答お願いします。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?