# \[SOLVED\] I can't find a material in a scene if isn't applied to a mesh

**URL:** <https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414>\
**Category:** Questions\
**Created:** [December 13, 2023, 9:57pm UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414 "2023-12-13T21:57:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guido\_Camerlingo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guido_camerlingo/32/36614_2.png) [@Guido\_Camerlingo](https://forum.babylonjs.com/u/Guido_Camerlingo)\
**Post date:** [December 13, 2023, 9:57pm UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/1 "2023-12-13T21:57:28Z")

</div>

Hi everyone,  
I have a .babylon file with some meshes with some materials appllied, in the same file i have others material not applied to any mesh. When i try to find material by name i cannot find the materials not applied to a mesh.

The goal is to replace materials between meshes

Thanks a lot

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [December 13, 2023, 11:06pm UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/2 "2023-12-13T23:06:38Z")

</div>

Hello and welcome!

Is it possible to share your .babylon file to have a look?

---

<div class="post-metadata">

**Author:** ![Guido\_Camerlingo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guido_camerlingo/32/36614_2.png) [@Guido\_Camerlingo](https://forum.babylonjs.com/u/Guido_Camerlingo)\
**Post date:** [December 14, 2023, 8:14am UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/3 "2023-12-14T08:14:16Z")

</div>

![babylo](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/2/3281f82dc6f72707366d6ddeedbac057178f291b.jpeg)

Thanks for the welcome!

I couldn’t share it, I’ll send a screenshot. From the sandbox I can change with a material not combined with a mesh but present in the babylon file. Via javascript I can’t find it in the scene I don’t know if I’m doing something wrong! Or is there a specific way. Should I find it if I search for it by id in the scene? I use assetsmanager to upload.

Thank you

---

<div class="post-metadata">

**Author:** ![MarianG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mariang/32/138_2.png) [@MarianG](https://forum.babylonjs.com/u/MarianG)\
**Post date:** [December 14, 2023, 8:43am UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/4 "2023-12-14T08:43:38Z")

</div>

Hi, just make sure your object (+ materials) is fully loaded when you search for material

---

<div class="post-metadata">

**Author:** ![Guido\_Camerlingo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guido_camerlingo/32/36614_2.png) [@Guido\_Camerlingo](https://forum.babylonjs.com/u/Guido_Camerlingo)\
**Post date:** [December 14, 2023, 9:49am UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/5 "2023-12-14T09:49:01Z")

</div>

ita loaded. I’ll do the change later via the interface. So if the material is in the file but not in the scene I should still find it by doing scene.getmaterialbyid ?correct?

Thanks

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [December 14, 2023, 10:15am UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/6 "2023-12-14T10:15:18Z")

</div>

Hi and welcome to our Community 😃

First things first, as said above, the material needs to be loaded in the scene. To ensure this, you can use the Inspector (i.e. in the PG or in scene) after scene is fully loaded. Like it appears you did from your screenshot. If the material is there once the scene is fully loaded, it likely means that you are trying to access the material BEFORE it’s loaded.

Loading async, through asset manager or a promise of any kind, you need to wait for the material to be loaded before attempting to access it. Else, it will generate an error (open the console to see that). The generated error will also prevent a number of script actions following the error.

After load, there are a number of ways you can access a material in scene. Yes, you can do it by ID but you can also do it by the material name or by calling a mesh and requesting for it’s material, again with the option to do it by name or by id. Going even further, you can look for descendants of nodes and you can also look for just a part/split in either the name or id which you can use as an identifier.  
For whatever your strategy is, the most important thing is that, at the time you access it, the material (or mesh in case of mesh - or mesh AND material in case of accessing material through the mesh) NEEDS to be loaded in scene.

I hope this helps and again, welcome to the Community 🕶

---

<div class="post-metadata">

**Author:** ![Guido\_Camerlingo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guido_camerlingo/32/36614_2.png) [@Guido\_Camerlingo](https://forum.babylonjs.com/u/Guido_Camerlingo)\
**Post date:** [December 14, 2023, 2:52pm UTC](https://forum.babylonjs.com/t/solved-i-cant-find-a-material-in-a-scene-if-isnt-applied-to-a-mesh/46414/7 "2023-12-14T14:52:58Z")

</div>

> [@mawa](#):
>
> First things first, as said above, the material needs to be loaded in the scene. To ensure this, you can use the Inspector (i.e. in the PG or in scene) after scene is fully loaded. Like it appears you did from your screenshot. If the material is there once the scene is fully loaded, it likely means that you are trying to access the material BEFORE it’s loaded.
> 
> Loading async, through asset manager or a promise of any kind, you need to wait for the material to be loaded before attempting to access it. Else, it will generate an error (open the console to see that). The generated error will also prevent a number of script actions following the error.
> 
> After load, there are a number of ways you can access a material in scene. Yes, you can do it by ID but you can also do it by the material name or by calling a mesh and requesting for it’s material, again with the option to do it by name or by id. Going even further, you can look for descendants of nodes and you can also look for just a part/split in either the name or id which you can use as an identifier.  
> For whatever your strategy is, the most important thing is that, at the time you access it, the material (or mesh in case of mesh - or mesh AND material in case of accessing material through the mesh) NEEDS to be loaded in scene.
> 
> I hope this helps and again, welcome to the Community

Hi thanks to all for replies.  
I solved it by using **SceneLoader.Append** instead of **assetsManager.addMeshTask** that doensn’t loads materials are not bind to a mesh.

thank you all, I hope to soon be able to contribute to this forum by increasing my skills.
