Hi there. The change event is working for html but not js. What am I doing wrong?
// find the asset by name in the registry
let asset = this.app.assets.find("storeInfo-test.js","script");
if(!asset){
console.log("couldn't not find",asset);
return;
}
asset.on('change', ()=> {console.log("asset was changed:",asset);});
Change event is never fired when the js is changed. If I use the same code with html it does fire.
Hi @noah_mizrahi,
I think .js (script) assets are treated differently, than regular assets.
What are you trying to do? Re-run a script in your launch window after it has been updated?
For that you can use hot-reload, which is already built in the Playcanvas editor. Check this:
https://developer.playcanvas.com/en/user-manual/scripting/hot-reloading/
For this purpose hot-reloading won’t work. We are using our own class structure defined in js and using a script attribute will be too cumbersome.
Ah I see, did you try the load event then?
For shaders this event I am sure will fire each time the file is updated.
For script assets I will have to check if that is the case.
I don’t think the load event runs unless the change event happens. I think I’m going to look at moving to a local build to solve some of these issues. Thank you!
1 Like