How do you dispose the actions of an ActionManager

Hey guys,

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:

disposeActionManager(actionManager: AbstractActionManager) {
actionManager.actions.forEach(action => actionManager.unregisterAction(action));
actionManager.dispose();
}

Thanks,
Irinel

Hello! actionManager.dispose() should be enough

Do you have a repro (in the playground) demonstrating the issue?

Hi there,

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.

Can you repro it in the Playground?

Sure, thanks @carolhmj,

I think this is a good example of the issue:

Why is it still triggering a log once I dispose of the action manager? Maybe I’m missing something.

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?

@phaselock that did the trick, thanks.

this.meshController.mesh.actionManager.dispose();
this.meshController.mesh.actionManager = null;
1 Like

This should be taken care of on the dispose, I’m opening a PR to do it: Clean up mesh.actionManager attribute when it is disposed of. by carolhmj · Pull Request #14138 · BabylonJS/Babylon.js (github.com)

3 Likes

Hey @carolhmj,

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

Thanks!

1 Like

Hello! Thanks for the report, I modified the logic so that calling dispose on a mesh only disposes of the action manager if it is not shared :slight_smile: fix action manager disposal when shared by carolhmj · Pull Request #14267 · BabylonJS/Babylon.js (github.com)

2 Likes

Thanks for the quick reply Carol ! :heart_eyes:

2 Likes

Hi @carolhmj,

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 :slight_smile:. 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.

Hey @tibotiber, what’s happening is when a mesh is disposed and it’s not sharing its action manager, the action list is getting unregistered,

I’ve dealt with the same issue, and ended up creating a small function that registers the action if none is found.

but I do love the idea behind having an option to control this behavior.

Yep, exactly what I understood as well. My main issue is this is a new behavior, so it breaks my app, and maybe others :wink: .

Cc @amoebachant eho owns our input area

I’m totally game to add an option for you folks to let the system acts with the original behavior

2 Likes

should be easy to add,
here, I submitted a quick PR

1 Like

Super quick @MeshSlayer :saluting_face:

1 Like

Just to close the loop and confirm that this solved the issue. Here is the updated PG using the new option:

And I’ve just pulled v7.11.2 in my app and it works like a charm. Thanks again @MeshSlayer :slight_smile:

Edit: would it also be a good idea to add this to the relevant release as breaking change and advice to keep the old behaviour?

1 Like

Awesome ! Glad to help.

I think we add a small section within the docs. Should be helpful

Cool, I’ll look at adding that tomorrow. Should be a fairly straight forward PR :sweat_smile:

1 Like