LoginSignup
0
0

[UEFN][Verse]GamePlayTagを使ってレベル上のアクターにVerseからアクセスする

Last updated at Posted at 2023-10-19

はじめに

UE5でも存在する「GamePlayTag」が、UEFNでも使用可能ということで使い方をメモします。
Unityの「Tag」と近い使用感で、アクターにタグを付けることで、レベル上にあるアクターやデバイスの情報にVerse上からアクセスすることができます。

GamePlayTagをざっくり説明

元々のUEのドキュメントでは

Gameplay Tag は概念的なものであり、ユーザー定義の名前を持つ階層ラベルです。

と説明されています。個人的にポイントは 階層ラベルという点で、Unityと違って階層的にラベリングできるところが便利ポイントに見えます。階層ラベルのイメージは以下です。
image.png

UEFNでのGamePlayTag

UEFNでタグ付けできる要素は

  • 小道具 (Prop)
    • Fortnite Creativeで提供されているMeshActor
    • 自ら作成するBuilding Prop
  • 既存の仕掛け (Devices)
  • Verseで作成した仕掛け

です。

GamePlayTagを定義する

Verseファイル上でTag名を定義する必要があります。

例えば

  • major_tags
    • editable_tags
  • minor_tags
    • spatial
    • normal

といったタグを定義したいとしましょう。以下のようなVerseファイルを作ります。

tag.verse
using { /Verse.org/Simulation/Tags }

major_tags := class(tag){}
editable_tags := class(major_tags){}
minor_tags := class(tag){}
spatial := class(minor_tags){}
normal := class(minor_tags){}

GamePlayTagを割り当てる

  • UEFN の [Outliner (アウトライナー)] で、タグ付けするActorを選択し、[Details (詳細)] パネルを開きます。
  • [Details] パネルで、[Add New Component (新しいコンポーネントを追加)] をクリックして、ドロップダウンから [Verse Tag Markup] を選択します。

image.png

  • VerseTagMarkup コンポーネントを選択し、[Details] パネルにその設定を表示します。
  • [Gameplay Tags (ゲームプレイ タグ)] で、Tags プロパティを編集し、GameplayTagを追加します。この例では、editable_tagsが仕掛けに追加されます。

image.png

GamePlayTagでVerseコードからアクターを見つける

GetCreativeObjectsWithTag(tag{})を使って次のように、アクターを検索することができます。

TaggedActors := GetCreativeObjectsWithTag(editable_tags{})

これでeditable_tagsタグのついたアクターをVerseから見つけることができます。

for文でタグがついたものを検索し、if文でフィルタリングします。

TaggedActors := GetCreativeObjectsWithTag(editable_tags{})
    for (TaggedActor : TaggedActors):
        if(Prop := creative_prop[TaggedActor]):
            Prop.Hide() //Propに関する処理

このif文のフィルタリングが難しいので更に説明します。

if文でフィルタリングする方法

次の文がやっていることはTaggedActorの中でcreative_prop型にキャストできるもののみを取り出す。といった処理です。

if(Prop := creative_prop[TaggedActor]):

では、どのようなclassがキャストできるでしょうか。

VerseのソースコードのDevices周りのクラス図を可視化するとわかります。

GetCreativeObjectsWithTagの返り値の型はcreative_object_interface[]です。つまりcreative_object_interfaceを実装しているもの、継承しているものがキャストできるものの対象になります。

Monosnap data_image_svg+xml;base64,PD94bWwgdmVyc2l.png

図から次のようなclassにアクセスできることがわかります。

  • creative_device_base (Fortniteが用意した仕掛け/Deviceすべて)
    • score_manager_device (スコア管理するデバイス)
    • その他100種類以上のデバイス
  • creative_prop
    • Fortniteが準備したMeshActor
    • 自分でBuildingPropで作ったActor
  • creative_device (Verseで作成した仕掛けのすべて)
    • original_verse_device (Verseで作成した仕掛けの具体class)

major_tagsで取得したActorをそれぞれフィルタリングすると次のような実装になります。

AllCreativeObjects : []creative_object_interface := GetCreativeObjectsWithTag(major_tags{})

# major_tags を持つすべての creative_prop アクタの位置をプリントします
for (Prop : AllCreativeObjects):
    if (Prop := creative_prop[Prop]):
        Print("Prop found with all_tag at position: {Prop.GetTransform().Translation}")

# major_tags を持つすべての仕掛けアクタの位置をプリントします
for (Device:AllCreativeObjects):
    if (Device := creative_device_base[Device]):
        Print("Creative device found with all_tag at position: {Device.GetTransform().Translation}")

# major_tags を持つすべての「Verse で作成した仕掛け」アクタの位置をプリントします
for (VerseAuthoredDevice : AllCreativeObjects):
    if (VerseAuthoredDevice := creative_device[VerseAuthoredDevice]):
        Print("User device found with all_tag at position: {VerseAuthoredDevice.GetTransform().Translation}")

おまけ: plantumlから生成されたもの

もっと大規模に

0
0
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
0
0