Dispose() function on InstantiatedEntries?

Hey team,
Can we have a dispose function on BABYLON.InstantiatedEntries included in core?

When using AssetContainer.instantiateModelsToScene() to clone a set of character assets, animations, etc, i couldn’t find a built-in function for disposing just 1 specific instance of the container

BABYLON.InstantiatedEntries.prototype.dispose = function(){



All of those elements will be disposed individually when the scene disposes, as they are registered with the scene. There is no problem adding a “disposeEntries()” function (exactly the function you have provided), but when should it be called? Or is it just for you to be able to dispose them? in that case a help function on this class would be more than enough

Yeah, so basicly i instantiate models from an asset container multiple times to clone it correctly with animationGroups retargeted and everything.

Now i want to remove a specific model, say the " b " instance of the container from the PG scene.
Disposing the rootNode wont dispose skeletons or animationGroups, so a overall dispose function would be super helpful.

the dispose functions are called automatically, so I will prefer not to name it “dispose” , but “removeFromScene” or even “disposeFromScene” makes sense to me. Want to offer a PR?

Sure thing :slight_smile:

1 Like

Tried here: Update assetContainer.ts by aWeirdo · Pull Request #13451 · BabylonJS/Babylon.js · GitHub

But it says formatting/linting fail,
i don’t really use typescript & copy/pasted from the assetContainer dispose function, so i’m not sure what it wants from me :smiley:

Finishing: Formatting
[warn] packages/dev/core/src/assetContainer.ts
[warn] Code style issues found in the above file. Forgot to run Prettier?
##[warning]Couldn’t find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1

you should run the formatter :slight_smile:

npm run format:fix

Hey all,

I’m trying to call .dispose() on an InstantiatedEntries object but it doesn’t seem to have any effect.
I just ran npm upgrade to babylonjs version 5.46.0. Any insights?

Just tried, it is working for me:

But maybe something went wrong while upgrading?


want to share code/reproduction?

Hey thanks, @Takemura! It may be related to my npm/webpack configuration, or some part of my implementation. As long as I know that it works for others I’ll keep trying to make it work in my environment.

@RaananW I may share a reproduction environment but I’m leaning towards trying to solve it myself for now. Appreciate the offer/suggestion, thank you!

1 Like

@MacNaughty double-check your console if you have the right version, could be a caching issue aswell.
should say something simular to:

Babylon.js v5.46.0 - WebGL2 - Parallel shader compilation

but then again, it should have thrown a error trying to call a function that doesn’t exist

I got it figured out, turned out to be an implementation error I’d made an had been too tired to debug properly until today. @aWeirdo that is indeed the message I’m seeing after upgrading, I appreciate your help.

And thanks everyone for the support! I’ve been a lurker for some time now and am excited to have joined the discussion :smiley:

I have a question about using rotation quaternions that I’ll start another thread about, with a proper reproduction environment.

P.S. This community is awesome