# Hiding/showing a mesh with freezeActiveMeshes

**URL:** <https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306>\
**Category:** Questions\
**Created:** [October 5, 2021, 9:14am UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306 "2021-10-05T09:14:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [October 5, 2021, 9:14am UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/1 "2021-10-05T09:14:11Z")

</div>

Dear community,

We are currently having performance issues and experimenting with “freezeActiveMeshes” as detailed in this page:

> **[Optimizing Your Scene | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/scene/optimize_your_scene)**
>
> Learn how to optimize your scene in Babylon.js.

It works fine, however, I have issues with quickly showing and hiding a mesh. If I change the visibility via setEnabled or isVisible, it is not updated - I have to unfreeze/freeze active meshes which is too expensive.

I created a PG example:  
[https://www.babylonjs-playground.com/#BYVXY4](https://www.babylonjs-playground.com/#BYVXY4)

The ground is supposed to be shown/hidden if the sphere is clicked. Is there any option to show/hide a mesh quickly without calling unfreeze/freezeActiveMeshes on the scene?

Kind regards  
Zacherl

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [October 5, 2021, 9:23am UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/2 "2021-10-05T09:23:29Z")

</div>

One solution is to simply move the mesh out of camera view when needing to hide it

---

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [October 5, 2021, 9:36am UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/3 "2021-10-05T09:36:35Z")

</div>

Is this the way to go or are there other options? It seems a bit hacky.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 5, 2021, 2:42pm UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/4 "2021-10-05T14:42:01Z")

</div>

In your case you should not freeze the mesh themselves : [https://www.babylonjs-playground.com/#BYVXY4#1](https://www.babylonjs-playground.com/#BYVXY4#1)

Or unfreeze/freeze only the mesh on demand not the full scene: [https://www.babylonjs-playground.com/#BYVXY4#2](https://www.babylonjs-playground.com/#BYVXY4#2) But as this is internal only the API might change, @Deltakosh I wonder if there should be a kind of lambda based function to apply changes to a frozen list ???

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [October 5, 2021, 7:35pm UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/5 "2021-10-05T19:35:50Z")

</div>

@zacherl  
Didn’t have time earlier, other options covered by @sebavan are good non-hacky methods 🙂

If mesh.\_freeze / \_unfreeze were to be exposed that would be great.

Just throwing in a sample for completeness.  
[https://www.babylonjs-playground.com/#BYVXY4#5](https://www.babylonjs-playground.com/#BYVXY4#5)

---

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [October 6, 2021, 11:36am UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/6 "2021-10-06T11:36:57Z")

</div>

Thank you for all your feedback!

@sebavan , I tried to use your second solution, but I found a slight problem - if the mesh is disabled at the beginning, it does not work. I modified your PG:

[https://www.babylonjs-playground.com/#BYVXY4#6](https://www.babylonjs-playground.com/#BYVXY4#6)

See line 29/30 for the change. Can I do something to fix it?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 6, 2021, 2:38pm UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/7 "2021-10-06T14:38:57Z")

</div>

Yup this is exactly why those both functions are not publicly exposed as they intent to be as fast as possible in the restricted situation they are meant to be used.

In your case the simplest is enable all your meshes and set `mesh.alwaysSelectAsActiveMesh = true;` A couple frame after once the scene is fully ready disable/enable what you want with the previous hack.

---

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [October 7, 2021, 4:08pm UTC](https://forum.babylonjs.com/t/hiding-showing-a-mesh-with-freezeactivemeshes/24306/8 "2021-10-07T16:08:07Z")

</div>

Thanks a lot for your answers! We decided to move the mesh out of the camera sight for the moment, so we’ll go with the first option.
