以下の内容はhttps://baba-s.hatenablog.com/entry/2021/11/15/080200より取得しました。


【Unity】Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead.

概要

using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var gameObject   = Selection.activeGameObject;
        var lineRenderer = gameObject.GetComponent<LineRenderer>();
        lineRenderer.materials[0] = AssetDatabase.GetBuiltinExtraResource<Material>( "Sprites-Default.mat" );
    }
}

たとえば上記のようなエディタ拡張を書いて実行した時に

Instantiating material due to calling renderer.material during edit mode. 
This will leak materials into the scene. 
You most likely want to use renderer.sharedMaterial instead.

このようなエラーが出る場合は

using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var gameObject   = Selection.activeGameObject;
        var lineRenderer = gameObject.GetComponent<LineRenderer>();
        lineRenderer.sharedMaterial = AssetDatabase.GetBuiltinExtraResource<Material>( "Sprites-Default.mat" );
    }
}

sharedMaterial でマテリアルを設定するとエラーが出なくなります




以上の内容はhttps://baba-s.hatenablog.com/entry/2021/11/15/080200より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14