title: Change particle system material Unity 3D script
body: <p>I am trying to create particles emission for my objects which are actually pawns in a chess game. I changed particles material using Inspector for particle system and it works fine, however, when I try to change it with a script, nothing happens (particles stay pink for the black pawn). </p>
  
  <p>I am not sure what is wrong with the script, whether it's a change of material problem or maybe I need to set the path for material. I would be glad if someone suggested a solution!</p>
  
  <p>Here is the script:</p>
  
  <pre><code>public class BlackPawnParticleSystem : MonoBehaviour 
  {
      private Material m_Material;
      private ParticleSystemRenderer psr;
  
      private void Start() 
      {
          var ps     = GetComponent&lt;ParticleSystem&gt;();
          m_Material = GetComponent&lt;Renderer&gt;).material;
          psr        = GetComponent&lt;ParticleSystemRenderer&gt;);
  
          psr.material = Resources.GetBuiltinResource&lt;Material&gt;("BlackBishop.mat");
      }
  </code></pre>
  
  <p>This is how it looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/XxtJD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XxtJD.jpg" alt="enter image description here"></a></p>
  
  <p>EDIT:</p>
  
  <p>Changes in code:</p>
  
  <pre><code>public class BlackPawnParticleSystem : MonoBehaviour 
  {
      private Material m_Material;
      private ParticleSystemRenderer psr;
  
      private void Start() 
      {
          var ps       = GetComponent&lt;ParticleSystem&gt;();
          m_Material   = GetComponent&lt;Renderer&gt;().material;
          psr          = GetComponent&lt;ParticleSystemRenderer&gt;();
          psr.material = Resources.Load&lt;Material&gt;("BlackBishop");
      }
  </code></pre>
  
  <p>Location of my materials:
  <a href="https://i.stack.imgur.com/rtsaJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rtsaJ.jpg" alt="enter image description here"></a></p>
  
  <p>Inspector for the material:</p>
  
  <p><a href="https://i.stack.imgur.com/sSz7h.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sSz7h.jpg" alt="enter image description here"></a></p>
  
  <p>Script attached to the object:</p>
  
  <p><a href="https://i.stack.imgur.com/zeWA5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zeWA5.jpg" alt="enter image description here"></a></p>