
初歩的な内容だと思いますが、UnityのML-Agentsで実行時に発生したエラーがあったため対処不法など備忘録もかねて書き残しておきます。
1.内容
UnityのML-Agentsで実行時に以下のようなエラーが発生しました。
外部から入手したオブジェクトにアクセスしようとした時に発生したものです。
"abcdefgh"はアクセス先のオブジェクトの名称です。
MissingComponentException: There is no 'Renderer' attached to the "abcdefgh" game object, but a script is trying to access it.
You probably need to add a Renderer to the game object "abcdefgh". Or your script needs to check if the component is attached before using it.
2.解決方法
原因は、エラーの中にもある通り該当のGameObjectに「Renderer」がないということです。
そのため、その内容に沿って「Renderer」を追加しました。
手順は以下のようになります。
-
Hierarchy で
該当GameObjectを選択 -
Inspector で
Add Componentボタンをクリック -
Rendererを検索(たとえばMesh RendererやSprite Renderer) -
適切な Renderer を追加
これにて、該当GameObjectに「Renderer」が追加され、発生していたエラーも解消されました。
以上が、「MissingComponentException: There is no 'Renderer' attached to the "abcdefgh" game object, but a script is trying to access it.」のようなエラーが出た時の対処方法になります。