スマート オブジェクトのクイック スタート

このガイドでは、AI Agent を使ってスマート オブジェクトを作成して使用する方法を説明します。

概要

スマート オブジェクト とは、レベル内に配置され、AI Agent とプレイヤーによるインタラクションが可能なオブジェクトです。これらのオブジェクトには、インタラクトに必要なすべての情報が含まれています。

大まかに言うと、スマート オブジェクトは、リザベーション システム全体で使用可能な一連のアクティビティをレベル内で表現します。このシステムではレベル内のすべてのスマート オブジェクトを継続的にトラックし、AI Agent によるスマート オブジェクトの「リザーブ (予約)」を可能にします。このため、リザーブされたスマート オブジェクトは再び使用可能になるまで、他の Agent では使用できなくなります。

目標

このクイック スタート ガイドでは、AI Agent を使ってスマート オブジェクトを作成して使用する方法について学習します。

目的

  • AI Agent がスマート オブジェクトに到達した際に使用可能な AI ゲームプレイ動作と動作定義を作成する。

  • アニメーション モンタージュの再生に動作定義を使用するスマート オブジェクトを作成する。

  • Behavior Tree と Behavior Tree タスクを使ってシンプルな AI 動作を作成する。

  • レベル内でスマート オブジェクトを見つけて使用できる AI Agent を作成する。

1 - 必要な設定

  1. サード パーソン テンプレートを使って新しい ブループリント プロジェクトを作成します。

  2. メインメニューから [Settings (設定)] > [Plugins (プラグイン)] をクリックし、[Plugins] ウィンドウを開きます。

    Open the Plugins window

  1. [Gameplay (ゲームプレイ)] セクションに行き、Smart Objects プラグインと AI Behaviors プラグインを有効にします。要求された場合は、エディタを再起動します。

    Enable the Smart Objects plugin

    Enable the AI Behaviors plugin

このセクションの結果

このセクションでは新しいプロジェクトを作成し、Smart Objects プラグインと AI Behaviors プラグインを有効にしました。これで、AI Agent の AI ゲームプレイ動作を作成する準備が整いました。

2 - AI ゲームプレイ動作を作成する

このセクションでは、Agent がスマート オブジェクトのスロットに到達した際に行う動作を定義するゲームプレイ動作とゲームプレイ設定ブループリントを作成します。

  1. コンテンツ ブラウザ 内で右クリックし、[Create Basic Asset (基本アセットの作成)] セクションの [Blueprint Class (ブループリント クラス)] を選択します。

    Create a new Blueprint Class

  1. [Pick Parent Class (親クラスを選択)] ウィンドウで [All Classes (すべてのクラス)] セクションを展開し、「Gameplay Behavior」と検索して選択します。[Select (選択)] をクリックして、新しいアセットに「BP_SO_Behavior_PlayMontage」と名前を付けます。

    Select the Gameplay Behavior class

  2. 新しいブループリント クラスを作成し、「Gameplay Behavior Config 」と検索して選択します。[Select (選択)] をクリックして、新しいアセットに「BP_SO_BehaviorConfig」と名前を付けます。

    Select the Gameplay Behavior Config class

  3. コンテンツブラウザ 内で BP_SO_BehaviorConfig をダブルクリックして開きます。[Details (詳細)] パネルに行き、[Behavior Class (動作クラス)] ドロップダウンをクリックします。[BP_SO_Behavior_PlayMontage] を選択します。ブループリントをコンパイルして保存します。

    Add the BP_SO_Behavior_PlayMontage to the Behavior Class

  4. コンテンツ ブラウザ 内で BP_SO_Behavior_PlayMontage をダブルクリックして開きます。[Functions (関数)] の隣にある [Override (オーバーライド)] ドロップダウンをクリックして OnTriggeredCharacter を選択します。

    Override the OnTriggeredCharacter function

  5. Event OnTriggeredCharacter ノードの Avatar ピンを右クリックして、[Promote to Variable (変数へ昇格)] を選択します。

    Right-click the Avatar pin of the Event OnTriggeredCharacter node and select Promote to Variable

  6. Avatar 変数を イベント グラフ にドラッグし、Get Avatar を選択します。Avatar ノードからドラッグして、「Get Component by Class」と検索して選択します。

    Search for and select Get Component by Class

  7. Component Class ドロップダウンをクリックし、「Skeletal Mesh Component」と検索して選択します。

    Add the Skeletal Mesh component

  8. イベント グラフ 内を右クリックし、「Play Montage」と検索して選択します。

    1. Get Component by Class ノードの Return Value ピンを、Play Montage ノードの In Skeletal Mesh Component ピンに接続します。

    2. Set Avatar ノードを Play Montage ノードに接続します。

    Add a Play Montage node

    Connect the Play Montage node to the Set Avatar node

  9. Play Montage ノードの Montage to Play ドロップダウンをクリックします。アニメーション モンタージュをリストから選択します。

    Select an animation montage to play

    使用可能なアニメーションがない場合は、Unreal Engine マーケットプレイスから「Animation Starter Pack」などの無料のアニメーション アセット パックを入手できます

  1. Avatar 変数を イベント グラフ にドラッグし、Get Avatar を選択します。Avatar ノードからドラッグし、「End Behavior」と検索して選択します。

    Add the End Behavior node

  2. Play Montage ノードの On Completed ピンと On Interrupted ピンを EndBehavior ノードに接続します。

    Connect On Completed and On Interrupted to the End Behavior node

  3. ブループリントをコンパイルして保存します。

    この例では、動作を終了させるために、Play Anim Montage ノードではなく Play Montage ノードの On Completed ピンと On Interrupted ピンを使用しています。こうすることで、アニメーションの再生が終了するまでスマート オブジェクトが占有されたままとなります。

このセクションの結果

このセクションでは、Agent がスマート オブジェクトのスロットに到達した際にアニメーション モンタージュの再生に使用する Gameplay Behavior ブループリントと Gameplay Config ブループリントを作成しました。これで、スマート オブジェクトで使用する動作定義を作成する準備ができました。

3 - Smart Object Definition データ アセットを作成する

このセクションでは、スマート オブジェクトの各スロットの動作を定義する SmartObject Definition データ アセットを作成します。

  1. コンテンツ ブラウザ 内を右クリックし、[Miscellaneous (その他)] > [Data Asset (データ アセット)] を選択します。

    1. [Pick Class for Data Asset Instance (データ アセットインスタンスのクラスを選択)] ウィンドウで、「Smart Object Definition」と検索して選択します。

    2. [Select] をクリックし、アセットを作成して「SO_Definition_PlayMontage」と名前を付けます。

    Select Miscellaneous - Data Asset

    Select the Smart Object Definition

  2. コンテンツ ブラウザ 内で SO_Definition_PlayMontage をダブルクリックして開きます。[Smart Object (スマート オブジェクト)] セクションまでスクロールして、[Slots (スロット)] の隣にある [+ (追加)] アイコンをクリックして新しいスロットを追加します。これが、AI Agent が動作の実行時に使用するスロットです。

    Click the Add (+) button next to Slots** **to add a new Slot

  3. [Default Behavior Definitions (デフォルトの動作定義)] の隣にある [+ (追加)] アイコンをクリックし、[Index 0]Smart Object Gameplay Behavior Definition を選択します。[Gameplay Behavior Config (ゲームプレイ動作設定)] ドロップダウンをクリックして BP_SO_BehaviorConfig を選択します。

    Add a new Default Behavior Definition

  4. ブループリントを保存して閉じます。

このセクションの結果

このセクションでは、スマート オブジェクトの各スロットと、そのデフォルトの動作を定義する SmartObject Definition データ アセットを作成しました。

4 - スマート オブジェクトを作成する

このセクションでは、レベル内で Agent によって検索および使用可能なスマート オブジェクトを作成します。

  1. コンテンツ ブラウザ 内で右クリックし、[Create Basic Asset (基本アセットの作成)] セクションの [Blueprint Class (ブループリント クラス)] を選択します。

    Create a new Blueprint Class

  2. [Pick Parent Class] ウィンドウで、[Actor (アクタ)] クラス ボタンをクリックしてアセットを作成します。新しいアセットに「BP_SO_RunBT」と名前を付けます。

    Select the Actor class

  3. コンテンツ ブラウザ 内で BP_SO_RunBT をダブルクリックして開きます。[Components (コンポーネント)] ウィンドウに行き、[+ Add (追加)] ボタンをクリックします。「Smart Object」と検索して選択します。

    Select the SOComponent component

  4. SmartObject コンポーネントを選択した状態で [Details] パネルに移動し、[Smart Object] セクションまでスクロールします。[Definition Asset (定義アセット)] ドロップダウンをクリックして SO_Definition_PlayMontage を選択します。

    Add the Definition Asset

  5. ブループリントをコンパイルして保存します。

このセクションの結果

このセクションでは、スマート オブジェクトを作成して、そのスロットのデフォルトの動作を定義する動作定義を追加しました。

5 - AI Agent の Behavior Tree を作成する

このセクションでは、AI Agent がレベル内でスマート オブジェクトを見つけて使用するために必要な動作を作成します。このために、1 つのシンプルな Behavior Tree と 2 つのカスタム Behavior Tree タスクを使用します。

Behavior Tree とブラックボードを作成する

  1. コンテンツ ブラウザ 内を右クリックし、[AI] > [Blackboard (ブラックボード)] を選択します。ブラックボードに「BB_SO_Agent」と名前を付けます。

    Create a Blackboard

  2. BB_SO_Agent をダブルクリックして開きます。[New Key (新しいキー)] ドロップダウンをクリックして [SmartObject Claim Handle (スマート オブジェクト クレーム処理)] を選択します。キーに「ClaimHandle」と名前を付けます。ブラックボードを保存して閉じます。

    Add a SmartObject Claim Handle

  3. コンテンツ ブラウザ 内を右クリックし、[AI] > [Behavior Tree] を選択します。Behavior Tree に「BT_SO_Agent」と名前を付けます。

    Create a Behavior Tree

Behavior Tree タスクを作成する

スマート オブジェクトを見つける

  1. コンテンツ ブラウザ 内で右クリックし、[Create Basic Asset (基本アセットの作成)] セクションの [Blueprint Class (ブループリント クラス)] を選択します。

    Create a new Blueprint Class

  2. [All Classes] セクションで「BT Task Blueprint Base」と検索して選択し、[Select] をクリックします。ブループリントに「BTT_FindSmartObject」と名前を付けます。

    Search for and select BT Task Blueprint Base, then click Select

  3. コンテンツ ブラウザ 内で BTT_FindSmartObject を右クリックし、[Duplicate (複製)] を選択します。新しいブループリントに「BTT_UseSmartObject」と名前を付けます。

    Duplicate BTT_FindSmartObject

  4. コンテンツ ブラウザ 内で BTT_FindSmartObject をダブルクリックして開きます。イベント グラフ 内を右クリックし、「Event Receive Execute AI」と検索して選択します。

    Add the Event Receive Execute AI node

  5. Event Receive Execute AI ノードの Owner Controller ピンからドラッグし、「Get Blackboard」と検索して選択します。

    1. Get Blackboard ノードの Return Value ピンを右クリックし、[Promote to Variable] を選択します。変数に「Blackboard」と名前を付けます。

    2. Event Receive Execute AI ノードを Set Blackboard ノードに接続します。

    Add the Get Blackboard node

    Connect the Set Blackboard node to the Event Receive Execute AI node

  6. Event Receive Execute AI ノードの Controlled Pawn ピンからドラッグし、「Get Actor Location」と検索して選択します。

    1. Get Actor Location ノードの Return Value からドラッグし、「Subtract」と検索して選択します。

    2. Get Actor Location ノードの Return Value からドラッグし、「Add」と検索して選択します。

    3. 両方のノードの XYZ の値をそれぞれ「2000」に設定します。これにより、Agent の周辺に 4000 x 4000 単位、もしくは 40 x 40 メートルの検索ボックスが作成されます。

    Add the Get Actor Location node

    Add Subtract and Add nodes

  7. イベント グラフ 内で右クリックし、「Make Box」と検索して選択します。

    1. Subtract ノードを Make Box ノードの Min ピンに接続します。

    2. Add ノードを Make Box ノードの Max ピンを接続します。

    Add a Make Box node

    Connect the Make Box node

  8. イベント グラフ 内で右クリックし、「Get Smart Object Subsystem」と検索して選択します。

    1. Smart Object Subsystem からドラッグして、「Find Smart Objects」と検索して選択します。

    2. Find Smart Objects ノードの Request ピンからドラッグし、Make SmartObjectRequest を選択します。

    Add a Get Smart Object Subsystem node

    Add a Find Smart Objects node

    Select Make SmartObjectRequest

  9. Make Box ノードの Return Value ピンを Make SmartObjectRequest ノードの Query Box ピンに接続します。

    1. Make SmartObjectRequest ノードの Filter ピンからドラッグし、Make SmartObjectRequestFilter を選択します。

    2. Make SmartObjectRequestFilter ノードの [Behavior Definition Class (動作定義クラス)] ドロップダウンをクリックし、SmartObjectGameplayBehaviorDefinition を選択します。

    3. Set Blackboard ノードを Find Smart Objects ノードに接続します。

    Connect the Return Value pin of the Make Box node to the Query Box pin of the Make SmartObjectRequest node

    Select SmartObjectGameplayBehaviorDefinition from the dropdown

  10. この時点でブループリントは次のようになります。

    The Blueprint so far

  11. Find Smart Objects ノードの Out Results ピンを右クリックして [Promote to Variable] を選択します。

    1. Out Results ノードのピンからドラッグし、「Is Valid Index」と検索して選択します。

    2. Is Valid Index ノードからドラッグし、「Branch」と検索して選択します。Out Results ノードを Branch ノードに接続します。

    Right-click the Out Results pin of the Find Smart Objects node and select Promote to Variable

    Select Is Valid Index

    Select Is Valid Index

  12. Branch ノードの False ピンからドラッグし、「Finish Execute」と検索して選択します。近接したスマート オブジェクトが検索基準に一致しない場合は、Out Results が無効になります。

    Drag from the False pin of the Branch node, then search for and select Finish Execute

  13. イベント グラフ 内に Smart Object Subsystem ノードを作成します。このノードからドラッグし、「Claim」と検索して選択します。

    1. Branch ノードの True ピンを Claim ノードに接続します。

    2. Out Results 変数を イベント グラフ にドラッグし、Get Out Results を選択します。このノードからドラッグし、「Random Array Item」と検索して選択します。

    3. Random ノードからドラッグし、Claim ノードの Request Results ピンに接続します。

    Add a Claim node

    Drag from the node, then search for and select Random Array Item

    Drag from the Random node and connect it to the Request Results pin of the Claim node

  14. Claim ノードの Return Value ピンを右クリックし、[Promote to Variable] を選択します。変数に「ClaimHandle」と名前を付けます。

    1. Claim Handle ノード ピンからドラッグし、「Is Valid Smart Object Claim Handle」と検索して選択します。

    2. Is Valid Smart Object Claim Handle ノードの Return Value からドラッグし、「Branch」と検索して選択します。

    Right-click the Return Value pin of the Claim node and select Promote to Variable. Name the variable ClaimHandle

    Drag from the Claim Handle node pin, then search for and select Is Valid Smart Object Claim Handle

    Drag from the Return Value of the Is Valid Smart Object Claim Handle node, then search for and select Branch

  15. Branch ノードの False ピンからドラッグし、「Finish Execute」と検索して選択します。

    Drag from the False pin of the Branch node, then search for and select Finish Execute

  16. Blackboard 変数を イベント グラフ にドラッグし、Get Blackboard を選択します。

    1. Blackboard ノードからドラッグし、「Set Value as SOClaim Handle」と検索して選択します。

    2. Branch ノードの True ピンを Set Value as SOClaim Handle ノードに接続します。

    3. Set Value as SOClaim Handle ノードの Key Name ピンを右クリックし、[Promote to Variable] を選択します。

    4. Key Name 変数を選択した状態で [Details] パネルに移動し、[Instance Editable (インスタンス編集可能)] チェックボックスをオンにします。[Default Value (デフォルト値)] を「ClaimHandle」に設定します。

    Drag from the Blackboard node, then search for and select Set Value as SOClaim Handle

    Right-click the Key Name pin of the Set Value as SOClaim Handle node and select Promote to Variable

    Enable the Instance Editable checkbox. Set the Default Value to ClaimHandle

  17. ClaimHandle 変数をドラッグして Set Value as SOClaim Handle ノードの Value ピンに接続します。

    Drag the ClaimHandle variable and connect it to the Value pin of the Set Value as SOClaim Handle node

  18. Set Value as SOClaim Handle ノードからドラッグし、「Finish Execute」と検索して選択します。ノードの Success チェックボックスをオンにします。

    Add a Finish Execute node and enable the Success checkbox

  19. ブループリントをコンパイルして保存します。

スマート オブジェクトを使用する

  1. コンテンツ ブラウザ 内で BTT_UseSmartObject をダブルクリックして開きます。イベント グラフ 内を右クリックし、「Event Receive Execute AI」と検索して選択します。

    Add the Event Receive Execute AI node

  2. Event Receive Execute AI ノードの Owner Controller ピンからドラッグし、「Get Blackboard」と検索して選択します。

    Drag from the Owner Controller pin of the Event Receive Execute AI node, then search for and select Get Blackboard

  1. Get Blackboard ノードの Return Value ピンからドラッグし、「Get Value as SOClaim Handle」と検索して選択します。

    Drag from the Return Value pin of the Get Blackboard node, then search for and select Get Value as SOClaim Handle

  2. Get Value as SOClaim Handle ノードの Key Name ピンを右クリックし、[Promote to Variable] を選択します。

    1. Key Name 変数を選択した状態で [Details] パネルに移動し、[Instance Editable (インスタンス編集可能)] チェックボックスをオンにします。[Default Value (デフォルト値)] を「ClaimHandle」に設定します。

    Enable the Instance Editable checkbox. Set the Default Value to ClaimHandle

  1. Get Value as SOClaim Handle ノードの Return Value ピンからドラッグし、「Use Claimed Smart Object」と検索して選択します。

    1. Get Value as SOClaim Handle ノードを Use Claimed Smart Object ノードに接続します。

    2. Event Receive Execute AI ノードの Owner Controller ピンからドラッグし、Use Claimed Smart Object ノードの Controller ピンに接続します。

    Drag from the Return Value pin of the Get Value as SOClaim Handle node, then search for and select Use Claimed Smart Object

    Drag from the Owner Controller pin of the Event Receive Execute AI node and connect it to the Controller pin of the Use Claimed Smart Object node

  2. Use Claimed Smart Object ノードの On Finished ピンからドラッグし、「Finish Execute」と検索して選択します。ノードの Success チェックボックスをオンにします。

    Drag from the On Finished pin of the Use Claimed Smart Object node, then search for and select Finish Execute

  3. ブループリントをコンパイルして保存します。

Behavior Tree を作成する

  1. コンテンツ ブラウザ 内で BT_SO_Agent をダブルクリックして開きます。Root ノードからドラッグして Selector を選択します。

    Drag from the Root node and select Selector

  2. Selector ノードからドラッグして Sequence を選択します。

    1. Selector ノードからドラッグして Wait を選択します。最初の検索が成功しなかった場合は、このノードにより、スマート オブジェクトを新しく検索する前に Agent が 5 秒間待機します。

    2. Sequence ノードが Wait ノードの左側にあることを確認してください。こうすることで、Behavior Tree 内で Sequence が最初に実行されることを確実にできます。

    Drag from the Selector node and select Sequence

  3. Sequence ノードからドラッグして BTT_FindSmartObjects を選択します。

    Drag from the Sequence node and select BTT_FindSmartObjects

  4. Sequence ノードからドラッグして BTT_UseSmartObjects を選択します。

    Drag from the Sequence node and select BTT_UseSmartObjects

  5. Sequence ノードからドラッグして Wait を選択します。このノードを選択した状態で、Wait Time を「2.0」に、Random Deviation を「0.5」に設定します。このノードにより、スマート オブジェクトを新しく検索する前に Agent が 1.5 ~ 2.5 秒間待機します。

    Drag from the Sequence node and select Wait

    Final Behavior Tree

  6. Behavior Tree を保存して閉じます。

このセクションの結果

このセクションでは、レベル内で Agent がスマート オブジェクトを見つけて使用できるようにするための Behavior Tree と Behavior Tree タスクを作成しました。

6 - AI Agent を作成する

このセクションでは、レベル内でスマート オブジェクトを検索する AI Agent を作成します。

  1. コンテンツ ブラウザ 内で ThirdPersonCharacter ブループリントをダブルクリックして開きます。

    Double-click the ThirdPersonCharacter Blueprint to open it

  2. イベント グラフ 内のすべてのノードを選択して削除します。イベント グラフ 内を右クリックし、「Event Possessed」と検索して選択します。

    Right-click in the Event Graph and search for then select Event Possessed

  3. Event Possessed ノードの New Controller ピンからドラッグし、「Cast to AI Controller」と検索して選択します。Event Possessed ノードを Cast to AIController ノードに接続します。

    Drag from the New Controller pin of the Event Possessed node, then search for and select Cast to AI Controller

  4. Cast to AIController ノードの As AIController ピンからドラッグし、「Run Behavior Tree」と検索して選択します。BTAsset ドロップダウンをクリックして BT_SO_Agent を選択します。

    Drag from the As AIController pin of the Cast to AIController node, then search for and select Run Behavior Tree

  5. ブループリントをコンパイルして保存します。

  6. コンテンツ ブラウザ 内で ThirdPerson_AnimBP ブループリントをダブルクリックして開きます。AnimGraph 内で右クリックし、「Default Slot」と検索して選択します。

    In the AnimGraph, right-click then search for and select Default Slot

  7. デフォルト のステート マシンを Slot ‘デフォルト スロット名' ノードの Source ピンに接続します。Slot ‘デフォルトのスロット名' ノードの出力を Output Pose ノードの Results ピンに接続します。

    Connect the Default state machine to the Source pin of the Slot ‘Default Slot' node. Connect the output of the Slot ‘Default Slot' node to the Results pin of the Output Pose node.

このセクションの結果

このセクションでは、レベル内でスマート オブジェクトを検索する AI Agent ブループリントを作成しました。また、アニメーション モンタージュが正しく再生されるように、アニメーション ブループリントを変更しました。

7 - スマート オブジェクトをテストする

作成した AI Agent をテストして、レベル内でスマート オブジェクトを見つけて使用できることを確認します。

  1. メイン ツールバーから [+ (コンテンツを追加)] > [Volumes (ボリューム)] > [NavMeshBoundsVolume] をクリックして、新しい ナビゲーション メッシュ アクタをレベルに追加します。レベルを覆うようにメッシュをスケーリングし、Agent が目的地まで移動できるようにします。

    Add a NavMeshBoundsVolume to your Level

  2. いくつかの BP_SO_RunBT ブループリントをレベルにドラッグします。

    Drag several BP_SO_RunBT** **Blueprints to your level

  3. ThirdPersonCharacter ブループリントをレベルにドラッグします。

    Drag the ThirdPersonCharacter** **Blueprint to your Level

  4. [Simulate (シミュレート)] をクリックして、レベル内で Agent がスマート オブジェクトを見つけて使用できることを確認します。

    Press Simulate to see the Agent find and use Smart Objects in the Level

このセクションの結果

このセクションでは、レベル内で AI Agent がスマート オブジェクトを見つけて使用できることを確認しました。

Unreal Engine のドキュメントを改善するために協力をお願いします!どのような改善を望んでいるかご意見をお聞かせください。
調査に参加する
キャンセル