Possible to communicate with actor component without class reference?

I’d like to use an Actor Component that attaches to the Player Controller to manage a menu system.

The component tracks active menu, previous menu, and has a few functions for handling “return to previous” menu, etc.

Motivation:
The reason I like to use the component is just because it’s easier to understand code if I get player controller, get it’s menu component, versus having a parent widget - I find it difficult to pass reference to a widget around and the code becomes hard to understand down the road.

Problem:
I can communicate with the Player Controller in a generic way via blueprint interface, but it seems that in order to communicate with a component of the Player Controller, I have to reference the component class directly, seen here:

This creates a dependency between the widgets and the MenuComponent:

The only way I can think to circumvent that is to have the Player Controller implement an interface, and then the interface events pass to the component, but that sort of defeats the point of using a component I think.

Just wondering if anybody has some ideas/examples how you might decouple a system like this. Ideally the component knows about the widgets but they don’t need to know about the component or the player controller, so their reference viewer should have no dependencies.

If it helps, here’s basic framework idea:

Also, is this something that’s only an academic worry? It’s a simple game, I doubt this sort of thing makes a difference, but I wonder if there is not better approach more aligned with unreals architecture or general programming best practices.

1 Like

It looks like the HUD class which is associated with the Player Controller will be better to use instead of a component.

It can be communicated with via interface without creating any hard references.

It also helps to not clutter my player controller with too much stuff.

I think this is the desired result:


The HUD, widget children of the HUD, and player controller all communicating but only depending on the interface.

1 Like

This is related and helpful as well:

Object references in Blueprints. Object references are one of the… | by Morva Kristóf | Advanced Blueprint scripting in Unreal Engine | Medium