AgentControllerのAgentを動的に変更する方法

Here is the forum to do the questions about how to use to Arbor developer.
Attention point:
  • We can not answer your questions about your project specific issues.
  • We can not answer your questions on Unity's specification issues.
  • Please check Arbor Documentation and ask a question if you still don't know how to use it. If the desired function is not described in the document, it is highly possible that the function does not exist from the beginning, so go to the request forum.

ここは、Arbor開発者へ使い方に関する質問を行うフォーラムです。
注意点:
  • ユーザー様のプロジェクトの仕様上の問題や設計に対する質問には答えられません。
  • Unityの仕様上の問題に対する質問には答えられません。
  • Arbor Documentationを確認の上、それでも使い方がわからない場合にご質問ください。欲しい機能の記載がドキュメントにない場合は機能が元から存在しない可能性が高いので要望フォーラムへ。

Forum rules
Here is the forum to do the questions about how to use to Arbor developer.
Attention point:
  • We can not answer your questions about your project specific issues.
  • We can not answer your questions on Unity's specification issues.
  • Please check Arbor Documentation and ask a question if you still don't know how to use it. If the desired function is not described in the document, it is highly possible that the function does not exist from the beginning, so go to the request forum.

ここは、Arbor開発者へ使い方に関する質問を行うフォーラムです。
注意点:
  • ユーザー様のプロジェクトの仕様上の問題や設計に対する質問には答えられません。
  • Unityの仕様上の問題に対する質問には答えられません。
  • Arbor Documentationを確認の上、それでも使い方がわからない場合にご質問ください。欲しい機能の記載がドキュメントにない場合は機能が元から存在しない可能性が高いので要望フォーラムへ。
karaage

AgentControllerのAgentを動的に変更する方法

Post by karaage »

NavMeshでのキャラの移動をキャラ以外のオブジェクトに付けたArborFSMで行わせていました。
Agent Move To Transfromを使用してキャラを目的地まで移動させていました。
プレハブより上の階層のオブジェクトは外れてしまうのでオブジェクトをプレハブにした際にAgentにアタッチしていたNavmeshAgentのついてるキャラの参照が外れてしまうのでスクリプトから生成時にAgentの中身をアタッチするシステムを作ろうとしたのですが、
AgentControllerのAgentを参照するタイミングがAwakeだったのでその手法は使えませんでした。
agentの中身を動的に変更する方法はありますでしょうか?Image
User avatar
caitsithware
管理人
Posts: 494
Joined: 2015/08/17 12:41

Re: AgentControllerのAgentを動的に変更する方法

Post by caitsithware »

図解していただきありがとうございます。

確かにAgentController.Awakeメソッドが呼ばれる時点でNavMeshAgentが設定済み前提の処理になっていました。
後からでも設定できるように変更いたします。

対応までの間の暫定対処方法は以下の通りです
  1. Assets/Plugins/Arbor/BuiltInBehaviours/Scripts/Components/AgentController.csを開く
  2. 538行目に以下の行を追加

    Code: Select all

    _StartPosition = agentTransform.position;
  3. 1160行目~1161行目を以下のように変更

    Code: Select all

    if (_Agent != null)
    {
    	agentTransform = _Agent.transform;
    	_StartPosition = agentTransform.position;
    }
    
この対処により、事前にNavMeshAgentを設定していなくてもAgentController.agentプロパティでNavMeshAgentを設定できるようになります。
ただし、他の場所でのNavMeshAgentのnullチェックは行っていませんので、移動呼び出しやUpdateが呼ばれる前に必ず設定するようご注意ください。
Guest

Re: AgentControllerのAgentを動的に変更する方法

Post by Guest »

ありがとうございます!!!
助かります!!!プレハブを置いたときに手動でセットするのが結構つらかったしアセットの処理を書き換えるのも抵抗あったのでとても助かります!
Post Reply