Freeze and unfreeze material

Hello :slight_smile:

I have trouble trying to unfreeze my material and update it then freeze it again, nothing seems to update

I have this simple demo here
https://www.babylonjs-playground.com/#EPI4MZ

1 Like

Hey @waverider404 !

You need to wait until after a render has completed to freeze the material. If you freeze straight away, the diffuseColor property will change, but the material won’t re-render, so you won’t see any difference in your scene. A simple fix is to freeze the material inside of onAfterRenderObservable().
Freezing materials | Babylon.js Playground (babylonjs-playground.com)

Does that work for you?

5 Likes

Awesome, thanks @DarraghBurke

2 Likes

One thing I did way back when freezing of computing world matrices was put in, was to set the internal property for freezing OFF (in case it was already ON), force a compute, then set it OFF. Babylon.js/transformNode.ts at master · BabylonJS/Babylon.js · GitHub

Not sure the same will work for materials, but this means if you wish it to be frozen most of the time, yet allow it to be unfrozen occasionally under your control, you only need to update the property, then (re-)freeze it. No need to unfreeze. Let the api do the unfreeze internally.

1 Like