Django Girls and Boys 備忘録

Python、Selenium、Django、java、iPhoneアプリ、Excelマクロなどで気付いたこと、覚えておきたいことなどを載せていきます。

【Unity】実行時に「MissingComponentException: There is no 'Renderer' attached to the "abcdefgh" game object, but a script is trying to access it.」というエラーが発生した時の対応方法


 初歩的な内容だと思いますが、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」を追加しました。

手順は以下のようになります。

  1. Hierarchy該当GameObjectを選択

  2. InspectorAdd Component ボタンをクリック

  3. Renderer を検索(たとえば Mesh RendererSprite Renderer

  4. 適切な Renderer を追加

 

 

 

これにて、該当GameObjectに「Renderer」が追加され、発生していたエラーも解消されました。

 

以上が、「MissingComponentException: There is no 'Renderer' attached to the "abcdefgh" game object, but a script is trying to access it.」のようなエラーが出た時の対処方法になります。