What should I do if I want to clean up all the Babylon scenes, models, lights, and materials?

I have 10 models. When I switch back and forth between these 10 models, I will create 10 game objects and my computer will become very stuck.

Canvas is in a pop-up window, and each time the pop-up window is opened, a new model is loaded

[image]
What should I do ?

Welcome back @haoguang_shen

Couple of clarifying questions I have… You have character game object and you want to switch the model shown? If this the same project you were working on last week? (For anyone else’s reference)

:slight_smile: I remember you were switching between 2 models with different materials and I suggested creating model each time. Are you disposing the original game object when you create the new one?
mesh.dispose(); If reloading is also too expensive of an option are you doing anything to cull the models/objects that are not being displayed on screen. Setting to inactive for example. This should help on the cost.

Let me know if this helps and feel free to ask follow up questions.

I will also throw out the old handy how to optimize your scene document. Really good resource just to have in general. Optimizing Your Scene | Babylon.js Documentation

Take a look at the “Scene with large number of meshes” and “Changing Mesh Culling Strategy” sections :wink: Let’s get this working at the fastest speed possible together!

Thanks for your reply, Because I switch models, I will clear all the content on the last canvas every time, even if I use mesh.dispose(), when I switch quickly (the first model has not been loaded yet, I will switch Another model), will cause both models to be displayed

I now use mesh.visibility = 0|1 to switch the model, I don’t know if this is good

1 Like

mesh.setEnabled(true/false) would probably highlight your intent more.

1 Like

Ok,I will try it again.

1 Like