Proper way to create an instance of a loaded GLB?

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!

Here you are :slight_smile:

PG -


Those are some good looking chicks!
Thanks @labris.

I hadn’t come across this method before. Just looking it up here. Cool that it can either clone or instance.


Oh also interesting. Looks like there is an AssetManager task type for loading AssetContainers, although doesn’t seem to have made it to the docs..

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.

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

1 Like

Huh, interesting.

So basically, that’s what I used to do, but I stopped because some models would just not render, bounding boxes display stopped working and a whole lot of other related things. For example, when you change the inserted but hidden models’ parent - instantiateModelsToScene stops working completely.

So - I suppose all of these are bugs?

Begrudgingly, what I do currently is hide the warnings and not call addAllToScene.

On that note - would it maybe be possible not to print this warning millions of times in the render loop?

I’m sure being told once per mesh would be fine… If it’s a warning, it doesn’t really warrant killing the developer console withing a minute of starting it, no? :slight_smile:


edit: maybe it wasn’t clear, but not calling addAllToScene makes all these strange issues go away for me. except those warnings.

1 Like

Hm, im not getting those artifacts with this method. Bounding boxes look good. No error messages. Added better naming, here:

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

1 Like

Here’s a playground trying to group assets added to the scene and instantiateToScene breaking:

And here’s one where the bounding boxes don’t show when addAllToScene is called:

Not sure how to reproduce models not being rendered at all in a playground when addAllToScene is called, but I assure you, it’s a thing.

I would be very thankful if that warning would just disappear. :slight_smile:

The main issues are:

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

Aside from making things invisible:

How do I properly move the instance parent? See here, if I move it after being instaniated once, instantiateToScene still breaks after:

I have thousands of models in a scene, them being loaded does not imply they will be instantiated immediately (or ever), also I’d like to use the inspector (which implies they can’t just all sit in the root, that makes the inspector rather unusable).

There is also the issue with the bounding boxes not being drawn: (try to enable them in the inspector).

I have a feeling that could be related to sometimes entire meshes not being drawn when addAllToScene is called (but sorry: no repro, will try again some day.

Back to that warning…

If it’s truly just a warning and not an error, it shouldn’t break the dev console. Could it maybe not be in the render loop?

This won t and should not work…

You are parenting container objects to scene ones…

You could reparent in your duplicate helper

Are they still container objects after calling addAllToScene?

Look, I’m not trying to be negative here, I just don’t see how this is supposed to work. Using addAllToScene has issues and that warning you get otherwise is absolutely not useful or helpful.

What is the right way?

Sure, instanced models go where they belong in the scene, but that’s also besides the point.

The point is, when you use addAllToScene, you end up with a lot of nodes in the root and you can’t move them otherwise instantiateToScene breaks…

I’m happy not to call addAllToScene, it works perfectly fine as far as I can tell. Only problem with that is that warning…


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.

It does work for me:

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.

It sure does work now. It absolutely wasn’t when I made the pg the other day. I distinctly remember trying to enable the bounding boxes on several of the instances. scratches head

I’ll have a look if I can figure out what’s going on there.

I suppose that’s a workaround that might do.

Maybe it’s something to consider “featurizing” - I can’t be the only one who wants to do this.


Here’s a playground with a model that will print hundreds of thousands of warnings to the log in a short time, addAllToScene called or not: (warning: will kill your dev console fast and might render your browser unusable).

Please, I beg of you: don’t print to the log in the render loop :frowning:

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

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:

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:


Let’s fix this! :slight_smile:

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

instantiateModelsToScene doesn’t take parents of clones nodes into account · Issue #13454 · BabylonJS/Babylon.js (