# Set parent of asset container

**URL:** <https://forum.babylonjs.com/t/set-parent-of-asset-container/28099>\
**Category:** Questions\
**Created:** [March 3, 2022, 12:54am UTC](https://forum.babylonjs.com/t/set-parent-of-asset-container/28099 "2022-03-03T00:54:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samevision](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@samevision](https://forum.babylonjs.com/u/samevision)\
**Post date:** [March 3, 2022, 12:54am UTC](https://forum.babylonjs.com/t/set-parent-of-asset-container/28099/1 "2022-03-03T00:54:35Z")

</div>

Hello guys,

I really like the asset container since it makes it very easy to clone meshes including their animations. But how am I able to set a new parent of the root mesh? It is possible but if I try to clone it after that everything breaks: [https://playground.babylonjs.com/#8RJEY8#1](https://playground.babylonjs.com/#8RJEY8#1)

Any idea how to avoid this?

Best

---

<div class="post-metadata">

**Author:** ![kaliatech](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kaliatech/32/13557_2.png) [@kaliatech](https://forum.babylonjs.com/u/kaliatech)\
**Post date:** [March 3, 2022, 1:32pm UTC](https://forum.babylonjs.com/t/set-parent-of-asset-container/28099/2 "2022-03-03T13:32:08Z")

</div>

Can you switch the order of operations? Instead of:

```auto
  root.setParent(parent)
  container.instantiateModelsToScene()

```

do:

```javascript
  container.instantiateModelsToScene()
  root.setParent(parent)

```

Example: [https://playground.babylonjs.com/#8RJEY8#2](https://playground.babylonjs.com/#8RJEY8#2)

---

<div class="post-metadata">

**Author:** ![samevision](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@samevision](https://forum.babylonjs.com/u/samevision)\
**Post date:** [March 3, 2022, 1:39pm UTC](https://forum.babylonjs.com/t/set-parent-of-asset-container/28099/3 "2022-03-03T13:39:54Z")

</div>

Thanks for your reply. That works but in my scene I don’t clone the mesh immediately but on demand. It seems to work if I unparent the mesh before cloning though. This hack is fine for me 🙂

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

---

<div class="post-metadata">

**Author:** ![samevision](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@samevision](https://forum.babylonjs.com/u/samevision)\
**Post date:** [March 3, 2022, 10:07pm UTC](https://forum.babylonjs.com/t/set-parent-of-asset-container/28099/4 "2022-03-03T22:07:56Z")

</div>

I have a question regarding the whole loading of meshes via containers: Is it expensive to keep container in the scene? I want to load multiple models on demand. So sometimes I load models A, B & C. Then I don’t need model B anymore, wherefore I call container.removeAllFromScene(). It can be possible that I need this model B later again. So what is better:

(A) I call addAllToScene()/removeAllFromScene() whenever I need the model.  
(B) I dispose the whole container and load the model with LoadAssetContainer() again.

It may be possible that I never need model B again. And of course I have more models than three. So I am very curious if I can go with method A.

Best

---

<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:** [March 4, 2022, 2:30pm UTC](https://forum.babylonjs.com/t/set-parent-of-asset-container/28099/5 "2022-03-04T14:30:10Z")

</div>

I really wonder what it would cost to allow a per model load/remove in asset container.
