Set parent of asset container

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

Any idea how to avoid this?

Best

Can you switch the order of operations? Instead of:

  root.setParent(parent)
  container.instantiateModelsToScene()

do:

  container.instantiateModelsToScene()
  root.setParent(parent)

Example: https://playground.babylonjs.com/#8RJEY8#2

2 Likes

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 :slight_smile:

2 Likes

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

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