title: Why I'm getting exception Instantiating material due to calling renderer.material during edit mode?
body: <p>In <code>EditorWindow</code> script type:</p>
  
  <p>Inside this method:</p>
  
  
  
  <pre class="lang-c# prettyprint-override"><code>public static void CopyData()
  {
      for (int i = 0; i &lt; selectedComponents.Length; i++)
      {
          if (selectedComponents[i])
          {
              if (copyTypeCount.ContainsKey(t[i]))
                  copyTypeCount[t[i]] = copyTypeCount[t[i]] + 1;
              else
                  copyTypeCount.Add(t[i], 1);
  
              for (int j = 0; j &lt; selectedFields[i].Length; j++)
              {
                  if (selectedFields[i][j])
                      fieldVals[i][j] = fields[i][j].GetValue(components[i]);
              }
  
              for (int j = 0; j &lt; selectedProperties[i].Length; j++)
              {
                  if (selectedProperties[i][j])
                  {
                      if (properties[i][j].CanRead &amp;&amp; properties[i][j].GetIndexParameters().Length == 0)
                          propertyVals[i][j] = properties[i][j].GetValue(components[i], null); //&lt;&lt;&lt;&lt;&lt; Problem here at this line
                      else
                          Debug.LogWarning(properties[i][j].Name + " could not be copied.");
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>On the line:</p>
  
  <pre class="lang-c# prettyprint-override"><code>propertyVals[i][j] = properties[i][j].GetValue(components[i], null);
  </code></pre>
  
  <p>The variable types for completeness:</p>
  
  <pre class="lang-c# prettyprint-override"><code>bool[] selectedComponents 
  
  Dictionary&lt;Type, int&gt; copyTypeCount
  
  Type[] t
  
  bool[][] selectedFields 
  
  bool[][] fieldVals
  
  List&lt;FieldInfo&gt;[] fields
  
  bool[][] selectedProperties
  
  List&lt;PropertyInfo&gt;[] properties 
  
  object[][] propertyVal 
  
  Component[] components 
  </code></pre>
  
  <p>The exception message:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>The complete exception message:</p>
  
  <blockquote>
    <p>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.
    System.Reflection.MonoProperty:GetValue(Object, Object[])
    ComponentCopier:CopyData() (at Assets/ComponentTester/Editor/ComponentTester.cs:265)
    ComponentCopier:OnGUI() (at Assets/ComponentTester/Editor/ComponentTester.cs:195)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)</p>
  </blockquote>
  
  <p>But no where in my script I'm doing any Instantiating or any renderer.material
  So I'm not sure why this exception is happened.</p>
  
  <p>The exception again is on the line:</p>
  
  <pre class="lang-c# prettyprint-override"><code>propertyVals[i][j] = properties[i][j].GetValue(components[i], null);
  </code></pre>
  
  <p>And line 195 is inside <code>OnGUI</code>:</p>
  
  <pre class="lang-c# prettyprint-override"><code>if (GUILayout.Button("Copy", GUILayout.Height(30)))
  {
      CopyData();
  
      if (closeAfterCopy == true)
      {
          this.Close();
      }
  }
  </code></pre>
  
  <p>Before the code was to <code>this.Close();</code> all the time to avoid this exception.
  But I don't want to close the window all the time so I added a check with a flag. But if it's not closed then I'm getting this exception.</p>