.dispose() does not hide all meshes

Hello there,

I am quite new to using babylon and this is an amazing tool, I can’t thank you enough for that :slight_smile:

I am trying to play with radio buttons letting me show or hide different meshes.

I had 3 meshes. A monkey exported from blender, the classic skull found on internet and a very simple torus from 3dsMax with no materials.

It worked great, i managed to do that successfully on these meshes and even change their colors etc.

I then tried to replace my torus by another mesh exported from 3dsMax but this one with textures (the IronMan).

But… IronMan never wants to disappear no matter what I do. I have tried a bunch of methods, .setEnabled(false); .dispose(); etc none of them having any effect on the IronMan, damn tony stark.

Here is my code (pretty simple), with the 3 babylon meshes that I use.

Do you guys have any idea?? This seems like a bug to me :confused:

PS: Also, if you have any advice to avoid using those global variables, I would gladly take that :slight_smile:

By the way, this error does look a lot the same than this one that mackey already pointed out :

has this been commited yet?

Thank you :slight_smile:

Yep :slight_smile:

Yes it was committed. And we need a repro in the playground to help.
Here is a doc to help you link to external content:
https://doc.babylonjs.com/resources/external_pg_assets

Also really useful, execute:

scene.debugLayer.show()

This will help you see the real meshes in your scene. Maybe you have clones or unwanted meshes, or you are calling dispose on the wrong ones

Thanks for the answers!

The thing is that the playground does not support external html code etc and in my case I have to interact with my babylon window from outside, this is why I used Radio Buttons.
I am afraid that if I use babylon to create GUI buttons in the playground this will fix my error assuming that the whole logic will be different, but this will not solve my problem, because I have to use external buttons…

Tell me if that wasn’t clear enough :slight_smile:

Well if you post here this is because you consider the problem is not on your code :wink: So a repro should be done in the playground where only babylonjs code runs

If the issue comes from outside of babylonjs then it is all under your control. If the problem can be reproduced in the playground and you can showcase that dispose does not work, I will gladly (and quickly) fix it

Often to trace a problem you need to simplify. It seems that the issue is with the ‘Iron Man’ import. So create a PG that imports the Iron Man. Once you are happy that it loads OK add a dispose() after it loads. No need for radio buttons. If Iron Man does not dispose then there is an issue to check, if it does dispose then the problem lies elsewhere.

I understand your point Deltakosh :slight_smile: I will manage to do so in my future posts.

I have figured out what my problem was.

It appears that with imports without materials, calling setEnabled(false) on newMeshes[0] is enough but if there is a material attached to it, you have to do a for loop on the length of it and disable it all. This is what I misunderstood there.

Still a big thanks for your answers :slight_smile:

1 Like

But… I have now another issue which I dont understand.

I can now successfully hide a mesh imported via ImportMesh() but assuming that I want my whole scene to be imported and not only the mesh, I have to use the .append() function, which I can’t manage to dispose.

Here is a playground explaining it better :

https://playground.babylonjs.com/#YQDNWY#2

Hi.
Parameter of callback from append function is a scene not array of meshes like in importMesh function
https://doc.babylonjs.com/how_to/load_from_any_file_type#sceneloaderappend

1 Like

uhh that’s right, thanks, I’ll investigate that :slight_smile: