Which is the preferred way to have "communication" between components of different owners?

So the question is pretty straightforward.

I have a door actor (containing DoorLogicComponent) , a cube actor (containing CubeLogicComponent) and a trigger volume.

The door must only open if trigger volume is stepped by a specific cube.

So I have a component on the door to move the door itself and have a reference to the TriggerVolume, however I need to communicate with the cube which has another component inside with logic (the CubeLogicComponent), I need to access a specific variable on CubeLogicComponent so the DoorLogicComponent can properly open the door to which is attached.

Does this make sense?

How can I communicate between components of different owners?

Thanks!

Look into blueprint interface and rethink your base approach.

I can have a reference to a actor of the world, and then find the component inside that actor, it’s easy I believe.
But would like to know the best way.
Thanks [USER=“3140864”]MostHost LA[/USER]

EDIT: This in cpp

Same thing. Interfaces are avaliable in anything. Just easier to set up in BP.
The cpp version is just an interface.

“Finding” stuff requires you to either smartly pass in a pointer and cast, or cast after “finding”. That’s just inefficient when the interface check can take care of it all.

Thank you for your help [USER=“3140864”]MostHost LA[/USER]
Just a side note: Even with interfaces I would still need a pointer to the AActor instance that implements that interface correct?

Because in my example, my door only opens if specific cube triggers the volume. And to know if the cube is the right one, I have another panel component indicating which cube reference is right.
So there is a third piece here as you can see. The door, the cube and the panel.
The door has easily access to the cube from the component that hit the trigger volume since I have a reference to the trigger volume on the door.

But then the door also needs a reference to the panel AActor to check if the cube hit matches the panel’s cube chosen.

I’ve read the link you sent, and not sure the interface could help here. I mean it would help because I dont need to cast from AActor variable to PanelComponent, could use reference a IPanelComponent. But would still need that reference variable on my Door.

Please correct me if I am wrong.
Thanks!

The overlap will provide the reference.
in both BP or Cpp

If only the right cube implement the interface all you need do is check for that.

Yes will provive the overlap of the cube on the volume, but what about the third element, I mean the panel?
The panel is not related with the cube, the panel is another component in the world.
Thanks.

EDIT: I believe I understand what you are saying, so when I spawn the cubes only one will actually implement the interface, so I will need two cubes classes, one that implements interface and another that doesn’t implement, if I got it right.

Managed it without having a instance reference to my Panel, using the interface. The panel generates the cubes which implement a interface and after generation marks each cube with a bool variable stating if it’s the right cube or not.

Then on the door i have access to the trigger panel, and I add a dynamic delegate (event handler) on actor begin overlap, then check if the actor implements the interface and then execute a an interface method which returns the variable previously assigned on spawn.

Thanks [USER=“3140864”]MostHost LA[/USER]

I believe this solution is better than the other I had before, and it’s not so expensive, casting the actor reference to MyCubeActor.

​​​​​​​All the best.

Keep in mind casting cost is next to 0, its more about not having to cast and being able to scale up/down however you need.
if you ever want something else to trigger the door, all you have to do is add the interface to it and set the variable you check.

Vs, having to go in and specifically cast to the new thing you added to check the variable.

That makes totally sense, I get it now, thanks for your insight and help on this!