Hi, I just started getting this strange error after switching scenes at runtime. It only points to engine code so I have no idea how to resolve it. Something to do with a button (maybe the button I pressed to switch scenes?..) Any hints greatly appreciated. Thanks
I had something similar recently. It was because I was destroying the button in the mouse event handler. I fixed it in the mouse event handler function with code like the following to allow the current call stack to empty before destroying the button. Maybe that could work in your case also.
I think its something to do with unregistering mouse/touch events in a similar way to an error I previously had however when I try to use the same solution that worked in a previous case (unregistering events when it gets destroyed) I just get a bunch of other errors (about hit padding??).
Thanks but honestly I wouldn’t know where to start to try to reproduce what’s going on because I really don’t know what the error is talking about. Your right, the project is highly data driven from the JSON.
The error occurs when I hit the ‘Product_Select_Button’
In debug (in the PC window) it says: Error loading scripts
In the console it says: Uncaught TypeError: Cannot read property ‘active’ of null
which points to ButtonComponent.get (playcanvas-stable.dbg.js:43169)
My previous scene is getting deleted as soon as the new scene loads which made me think that is what the unregistering of events was the issue, but when I unregister those events upon loading the scene I get:
Uncaught TypeError: Cannot read property ‘hitPadding’ of null
Start by gradually removing parts until the issue stops happening.
Eg.
We know it’s happening between scene loads. Does it occur if the scene with the button has the button already in the scene rather then adding it via code? If so, does it still happen when everything but the button is removed from the scene?
The scene that it loads, what happens if it’s an empty scene? Does the error still occur? etc
Hmm. Okay, if i wait a second before destroying the old Heirrachy I no longer get the error ie:
// Load the scenes entity hierarchy
this.app.scenes.loadSceneHierarchy(scene.url, function (err, parent) {
if (!err) {
console.log("About to destory old heirachy");
setTimeout(() =>
{
oldHierarchy.destroy();
}, 1000);
} else {
console.error(err);
}
});
So Im thinking that the de-registering of events or something weird with buttons continues to run for a frame or so even after the button entity is destroyed .
Think the code above would have any other negative impacts?
When that happens, I’ll just do another hack I guess
To me it seems that button events are still being accessed in the engine on playcanvas-stable.dbg.js:43169 or something for a frame after they get deactivated by my code?!?!?, but I have no access to that, and I really don’t know what I’m talking about anyway
I think its more nuanced than that as that would have been replicated in my test projects.
I think it’s related to the UI layout or style which is why going down a simple example by working backwards from a fork of the project is the way I would go and have done in the past.