# Proper way to create an instance of a loaded GLB?

**URL:** <https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478>\
**Category:** Questions\
**Created:** [January 18, 2023, 1:01am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478 "2023-01-18T01:01:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [January 18, 2023, 1:01am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/1 "2023-01-18T01:01:33Z")

</div>

Hi all.  
I’m getting errors when trying to instance a loaded GLB, “Instances should only be created for meshes with geometry.”

Reading up on past threads and see that we should use instantiateHierarchy on the loaded meshes array. Tried that, but the instance a) doesn’t seem to appear on screen and b) when moved to a different position using the inspector, throws the “with geometry” error.

Ideas? thx so much!

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

---

<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:** [January 18, 2023, 1:27am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/2 "2023-01-18T01:27:26Z")

</div>

Here you are 🙂

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/5/f5a6b22d9767576fd5d23dcb4f1f9fe53b79692d.jpeg)

PG - [https://playground.babylonjs.com/#WGZLGJ#7470](https://playground.babylonjs.com/#WGZLGJ#7470)

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [January 18, 2023, 2:16am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/3 "2023-01-18T02:16:57Z")

</div>

Those are some good looking chicks!  
Thanks @labris.

I hadn’t come across this method before. Just [looking it up here.](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/assetContainer.ts#L109) Cool that it can either clone or instance.

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [January 18, 2023, 2:31am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/4 "2023-01-18T02:31:01Z")

</div>

Oh also interesting. Looks like there is an [AssetManager task type for loading AssetContainers](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Misc/assetsManager.ts#L225), although doesn’t seem to have made it to the [docs.](https://doc.babylonjs.com/features/featuresDeepDive/importers/assetManager#available-tasks).

In my PG above, I’d simplified out the AssetsManager component to focus on the problem, but was then worried after seeing your example that it’d be incompatible with AssetsManager. Looks like there’s already a fix there though. Trying it shortly.

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [January 18, 2023, 2:49am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/5 "2023-01-18T02:49:12Z")

</div>

Nice, that was easy. Here’s the version using AssetsManager:

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

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [January 18, 2023, 5:33am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/7 "2023-01-18T05:33:39Z")

</div>

Hm, im not getting those artifacts with this method. Bounding boxes look good. No error messages. Added better naming, here: [https://playground.babylonjs.com/#WGZLGJ#7477](https://playground.babylonjs.com/#WGZLGJ#7477)

 ![Screenshot 2023-01-17 at 9.30.26 PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/e/eed7789ae4b37d5d966c278f1d83a8aa0392b4c3.jpeg)

Maybe post a PG of your stuff so we can see what’s happening with your models?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [January 18, 2023, 4:39pm UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/10 "2023-01-18T16:39:00Z")

</div>

The main issues are:

- you are making things invisible
- you changed the hierarchy before instantiating in the container

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [January 19, 2023, 12:29am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/12 "2023-01-19T00:29:46Z")

</div>

This won t and should not work…  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/8/88a144d20766fdbc01a7f2e26a734ff9db2226e7.png)

You are parenting container objects to scene ones…

You could reparent in your duplicate helper

---

<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:** [January 19, 2023, 10:32am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/15 "2023-01-19T10:32:26Z")

</div>

Doing:

```javascript
task.loadedContainer.rootNodes[0].parent = group;

```

won’t work, because the `instantiateModelsToScene` method only deals with root objects, i.e. objects with `parent === null`.

If what you want is parenting to avoid having lots of objects at the root level in the inspector, set a parent as you do, before calling `duplicate` do `task.loadedContainer.rootNodes[0].parent = null;` and after it returns set `task.loadedContainer.rootNodes[0].parent = group;` again.

> [@852Kerfunkle](#):
>
> There is also the issue with the bounding boxes not being drawn: [https://playground.babylonjs.com/#WGZLGJ#7480](https://playground.babylonjs.com/#WGZLGJ#7480) (try to enable them in the inspector).

It does work for me:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/5/759677a3725eff8c670ccaa1c015ff4b5c16b099.jpeg)

Note that “house task” is the initial object that you set to invisible after loading, so it’s expected the bounding box does not show up for these invisible objects.

---

<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:** [January 19, 2023, 4:19pm UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/18 "2023-01-19T16:19:48Z")

</div>

Actually, there’s a bug in `instantiateModelsToScene`, that’s why you get these warnings =\> you can see that the original tree is not instantiated correctly, some foliages are missing in the instances.

@RaananW It seems [this PR](https://github.com/BabylonJS/Babylon.js/pull/12904) does not handle the case where the instanced mesh is not at the root level but is a child of another mesh. Try this PG for eg:

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

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/4/d4b863ea0cecf7022c4709146cceb361d55c2e38.png)

The instance has the ground as the source mesh, instead of the sphere.

If using an empty mesh for the parent of the instance, you get the warnings @852Kerfunkle is experiencing:

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

And if you use a transform node as the parent, the `sourceMesh` property of the instance is pointing to the original sphere, not the cloned sphere:

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

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 19, 2023, 4:33pm UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/19 "2023-01-19T16:33:30Z")

</div>

Let’s fix this! 🙂

i’ll open an issue for that and follow up soon.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 19, 2023, 4:36pm UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/20 "2023-01-19T16:36:45Z")

</div>

[instantiateModelsToScene doesn’t take parents of clones nodes into account · Issue #13454 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/issues/13454)

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [February 23, 2023, 2:36am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/21 "2023-02-23T02:36:23Z")

</div>

Hm, this is not working anymore:  
[https://playground.babylonjs.com/#WGZLGJ#7477](https://playground.babylonjs.com/#WGZLGJ#7477)

Was working above. No errors, just not seeing the loaded asset. @RaananW, something change in the build regarding assetsManager.addContainerTask?

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [February 23, 2023, 3:30am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/22 "2023-02-23T03:30:38Z")

</div>

Never mind. Mesh was set to invisible.

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [February 23, 2023, 3:44pm UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/23 "2023-02-23T15:44:02Z")

</div>

Actually, i think something did change (b/c i dont think i posted an empty pg earlier!). How can you remove or hide the original mesh without impacting the clones? See this PG. Whenever I set the isVisible property of the original loaded mesh to false, it can’t be turned on again for the clones (as far as i can tell):

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 24, 2023, 12:45am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/24 "2023-02-24T00:45:11Z")

</div>

It is because you set the mesh invisible but are setting only the root visible again 🙂 [https://playground.babylonjs.com/#WGZLGJ#7924](https://playground.babylonjs.com/#WGZLGJ#7924)

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [February 24, 2023, 1:09am UTC](https://forum.babylonjs.com/t/proper-way-to-create-an-instance-of-a-loaded-glb/37478/25 "2023-02-24T01:09:19Z")

</div>

Ah, i thought node there was the mesh. Urg. Thx much.
