title: Qt3d Sceneloader: Replace the material component of an Entity with my custom material at runtime
body: <p>I have the following code to load a collada scene using the SceneLoader:</p>
  
  <pre><code>SceneLoader{
      id: sceneLoader
      source: "file:///home/rui/projects/cad/bodyplacement_lm36_v2.dae"
  
  
      MetalRoughMaterial {
  
          id:metal_mat
          objectName: "MetalRoughMaterial"
  
          metalness: 0
          roughness: 0.9
      }
  
  
      onStatusChanged: {
          console.log("SceneLoader status: " + status);
          if (status == SceneLoader.Ready) {
              console.log("Scene is ready");
  
              var entitynames=sceneLoader.entityNames();
              for (var i = 0; i &lt; entitynames.length; ++i) {
  
                  var entityname=entitynames[i];
                  var entityvar=sceneLoader.entity(entityname);
  
                  for (var j = 0; j&lt; entityvar.components.length; ++j) {
  
  
                      var cmp=entityvar.components[j]
                      if(cmp){
                          var cmp_class=cmp.toString();
                          if(cmp_class.indexOf("QPhongMaterial")&gt;=0){
                              entityvar.components[j]=metal_mat;
                          }
  
                      }
  
  
  
                  }
  
  
  
              }
  
  
  
          }
      }
  
  
  
  
  }
  </code></pre>
  
  <p>As stated in docs (<a href="https://doc.qt.io/qt-5/qt3drender-qsceneloader.html#details" rel="nofollow noreferrer">https://doc.qt.io/qt-5/qt3drender-qsceneloader.html#details</a>):</p>
  
  <blockquote>
    <p>The loader will try to determine the best material to be used based on the properties of the model file. If you wish to use a custom material, you will have to traverse the tree and replace the default associated materials with yours.</p>
  </blockquote>
  
  <p>After I iterate all the entities I try to replace the material component with the code:</p>
  
  <pre><code>entityvar.components[j]=metal_mat;
  </code></pre>
  
  <p>but it isn't working. After debugging I can see that the loaded material isn't replaced.</p>
  
  <p>How can I replace the material component with my custom material at runtime? </p>