How do you dispose all registered actions at once?
actionManager.dispose() doesn’t seem to do anything.
Do we have to keep track of all the actions and unregister them one by one?
At the moment I am doing this and it seems like scratching my ear behind my back as the actionManager already has the list of actions:
I seem to be having similar issue, my actionManager does not seem to be removing itself:
// line 126 - https://github.com/oriongunning/t5c/blob/main/src/shared/Entities/Entity/EntityMesh.ts
// register hover over player
this.mesh.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, (ev) => {
console.log("ACTION MANAGER HOVER");
let mesh = ev.meshUnderPointer;
for (const childMesh of mesh.getChildMeshes()) {
childMesh.overlayColor = new Color3(1, 1, 1);
childMesh.overlayAlpha = 0.3;
childMesh.renderOverlay = true;
}
})
);
and then when it is dead, I try to remove the action manager by doing :
// line 188 - https://github.com/oriongunning/t5c/blob/main/src/shared/Entities/Entity.ts
this.mesh.actionManager.dispose();
but the console.log is still triggering when I hover the mesh.
The reason want to remove the actionManager, is because I want to make sure players can easily pickup any drop items close to the mesh and want to remove any pointers or event on the enemy mesh that would prevent that.
I nulled the reference after the dispose. Garbage collection is not triggerable by dispose, this is how I usually do all my disposals. Does this work for you?
I’m sharing a single actionManager instance in my app for all the meshes.
after the fix you made, disposing a mesh will empty the actionManager actions list (without disposing the instance)
therefore, the possibility of sharing an actionManager instance is no longer reliable.
a condition to check if actionManager is linked to node should be called before emptying the actions list.
I’ve created a playground, make sure to switch back to an old version to compare the action manager behavior after deleting the sphere: https://playground.babylonjs.com/#J19GYK#566
I’m currently upgrading my app from BJS v5.27.0 to v7.11.0 and facing issues with hover states not working anymore. After extensive debugging I brought it down to this new behavior. In the old version, the action manager wasn’t disposed even if the last mesh was disposed, while the new version disposes of the action manager.
I definitely understand the rationale behind the change, as it keeps apps cleaner by default. So I’d like to support it. However, I think this should be considered as a breaking change, and communicated as such. Ideally it would also be useful to have an option on the actionManager to not auto flush itself to make backward compatibility easier to accomplish.
Some context in case it helps:
I’m building a digital twin data viz app. When the data refreshes, all interactive viz element meshes are disposed and replaced by new ones (this can happen at up to 60 fps when playing back historical data). The action manager is created once and reused for performance and code quality reasons (it’s managed in a completely separate place in the code).
Also because we can create an action manager without linking it to a mesh, it feels like an object with its own lifecycle, so disposing automatically based on meshes lifecycle is handy but not necessarily desirable I think. I think an optional behavior would be the best, no matter what you choose the default to be.
Happy to chat more about this . Take care.
Edit: I’ve created a PG to demonstrate the breaking change. The first 2s the boxes turn white on hover, then they’re recreated a bit further and still turn white on hover in v5, but not in v7.