# instantiateHierarchy throws errors for empty meshes

**URL:** <https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069>\
**Category:** Bugs\
**Tags:** instances\
**Created:** [February 9, 2023, 5:56pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069 "2023-02-09T17:56:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vlad160](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/vlad160/32/29740_2.png) [@Vlad160](https://forum.babylonjs.com/u/Vlad160)\
**Post date:** [February 9, 2023, 5:56pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/1 "2023-02-09T17:56:03Z")

</div>

Hello, community!

I’ve noticed strange regression while trying to update my project from Babylon 5.20.0 to 5.46.0.

Previously I had something like this and it was working fine.

> **[Babylon.js Playground](https://playground.babylonjs.com/#BET11L)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Now I see that 1 sphere is lost. In the Babylon inspector, I can see that instanced sphere doesn’t have a source (It is called “Clone of instance of sphere” in inspector). And there are a lot of warnings “Instances should only be created for meshes with geometry” in console. Any ideas? Is it forbidden to use meshes without geometry now?

---

<div class="post-metadata">

**Author:** ![Michael\_Prosser](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/michael_prosser/32/6062_2.png) [@Michael\_Prosser](https://forum.babylonjs.com/u/Michael_Prosser)\
**Post date:** [February 9, 2023, 8:15pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/2 "2023-02-09T20:15:40Z")

</div>

I put a single triangle in it with no bounds and it seems to fix your issue

> **[Babylon.js Playground](https://playground.babylonjs.com/#BET11L%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Likely the lack of vertexData is the issue and why WebGL is throwing warnings.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 9, 2023, 11:48pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/3 "2023-02-09T23:48:59Z")

</div>

cc @carolhmj as we did some changes lately to `instantiateHierarchy`.

---

<div class="post-metadata">

**Author:** ![Vlad160](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/vlad160/32/29740_2.png) [@Vlad160](https://forum.babylonjs.com/u/Vlad160)\
**Post date:** [February 10, 2023, 8:57am UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/4 "2023-02-10T08:57:57Z")

</div>

Yep, but it looks like a workaround for me. Since `instantiateHierarchy` should “instantiate (when possible) or clone that node with its hierarchy”. When I change table.instantiateHierarchy() to table.clone() it works fine.

---

<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:** [February 10, 2023, 12:14pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/5 "2023-02-10T12:14:31Z")

</div>

Yep. I have encountered the same recently. I found the only solution was to use clone or else your instanced children don’t come along.  
In fine, I cloned the lightest mesh with all instances parented to the object group. In some cases, I created an abstractMesh as a parent to clone the object group. As a side note, it also seems that in the process of cloning the hierarchy with all instances, some parameters of the cloned children instances are not kept when mirroring the cloned parent/group. In this case, Instances seem to loose their information of alphaIndex (not sure it this is new or has always been this way).

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [February 10, 2023, 1:43pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/6 "2023-02-10T13:43:15Z")

</div>



---

<div class="post-metadata">

**Author:** ![Vlad160](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/vlad160/32/29740_2.png) [@Vlad160](https://forum.babylonjs.com/u/Vlad160)\
**Post date:** [February 10, 2023, 3:55pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/7 "2023-02-10T15:55:16Z")

</div>

I think I found it.

> <https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Meshes/mesh.ts#L764>

Here we assume that the current mesh is always a source for instancedMesh but this assumption is not always correct. It requires the same fix as it was done here.

> <https://github.com/BabylonJS/Babylon.js/pull/13467>
>
> Fix #13454
> 
> I don't think there's any way around using some kind of dependency… graph to instantiate nodes in the correct order but if anyone has a simpler idea I'd love to hear it :D

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [February 10, 2023, 5:42pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/8 "2023-02-10T17:42:40Z")

</div>

Thank you very much for the report and investigation, I’ve added a fix here! [Fix to instantiate hierarchy by carolhmj · Pull Request #13524 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/13524)

---

<div class="post-metadata">

**Author:** ![Vlad160](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/vlad160/32/29740_2.png) [@Vlad160](https://forum.babylonjs.com/u/Vlad160)\
**Post date:** [February 10, 2023, 7:07pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/9 "2023-02-10T19:07:17Z")

</div>

Thanks a lot! Have wonderful weekend!

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [February 13, 2023, 12:57pm UTC](https://forum.babylonjs.com/t/instantiatehierarchy-throws-errors-for-empty-meshes/38069/10 "2023-02-13T12:57:00Z")

</div>


