Hi, Im trying to replace a render asset at runtime but I get an Error Loading scripts error with the following error in the console:
Uncaught TypeError: render.off is not a function
at RenderComponent._onRenderAssetLoad (component.js:774:20)
My code is simply as follows:
this.entity.render.asset = this.asset_variations[variation_index];
where the array asset_variations is of type ‘assets’ and contains a variation.glb file.
The variation.glb is set to preload in the editor but hasn’t been added to any scene. Maybe I need to do that or something? Is there a better way?
Any ideas?
Edit. I tried the following thanks to some chat GPT help. As usual it doesn’t work, but maybe I’m on the right track?:
// Check if the new model asset is loaded
if (this.asset_variations[variation_index].resource) {
// The new model is already loaded, so we can set it immediately
this.entity.render.asset = this.asset_variations[variation_index];
} else {
// Wait for the new model to load and then set it
this.asset_variations[current_game_product_state].on("load", function () {
this.entity.render.asset = this.asset_variations[variation_index];
}.bind(this))
}
Thanks