How to dispose material plugin?

Repro: https://playground.babylonjs.com/#PSUL78#2

Was expecting that disposing a material plugin would leave me with just the standard material but it appears that stuff other than the plugin was disposed as well. What is the correct way of disposing the material plugin w/o affecting my original material? Do I need to craft a custom dispose function in my plugin?

nvm, you cannot dispose a material plugin. You can only disable it. This is the way.

2 Likes

Yup cause once coupled within the material it is way too hard too manage removing it from already existing instances.

2 Likes

its might possible to add some example

  get isEnabled() {
    return this._isEnabled;
  }

  set isEnabled(enabled) {
    if (this._isEnabled === enabled) {
      return;
    }
    this._isEnabled = enabled;
    this.markAllDefinesAsDirty();
    this._enable(this._isEnabled);
  }

  _isEnabled = false;

  prepareDefines(defines: MaterialDefines) {
    defines["VAT"] = this._isEnabled;
  }

did you mean do it like this?
but it dose not work for me

Like this: https://playground.babylonjs.com/#PSUL78#3

Test with Line 33. Cheers!

thanks that is great

but I do this in another way

my material plugin is used on a specific mesh
I saved original material, and used original material clone for the mesh.
whenever I want a new (updated plugin) I dispose the last material and create a new one

is that fine?

Sorry, english isn’t my mother tongue so I’m not entirely sure what you mean. As long as it works, it should be fine. Otherwise, pls try reproducing in the playground so everyone can help.

Hope it helps, cheers!