How to communicate between Actor Component and Actor BP?

Hello,

I have my character BP which has a interact event implemented (it makes a line trace and if it checks against an interactable item it attaches it to hand). I did this through inheritance and a BP Interface. Basically, from the character BP we call the interface and the pick up logic is executed in the master blueprint.

I was trying to change this system to an Actor Component. I have simply copied the logic inside the master blueprint and added it to the component, then added the component to an Actor Blueprint (such as a sword), but nothing happens. How do I communicate between the component and the blueprint that it is attached to?

The component can talk to the actor:

  • by either getting an owner and casting / sending an interface message:

image

  • or by calling a dispatcher:

image

Which is caught by the actor owning said component:

The above can be done dynamically, too.


The actor can talk to the component directly:


If you were expecting a message an actor receives to propagate to components automatically, then it’s a no. But you can register it yourself:

Here, if the actor receives damage, the component will hear about it. It also works the other way round - a component can reach out to the owning actor and bind to what’s needed.

3 Likes
  1. What do you mean with dynamically?
  2. Which method is more efficient?
  3. In my case I have 2 blueprints that have to communicate and the Actor Component.
    The character BP does the line trace and calls an interface, the interface executes the logic in the Actor Component which is attached to the weapon blueprint. Do I need to do anything in the weapon blueprint or just by attaching the component is enough?

In case you spawn a component run-time. Because you can, and destroy them too, ofc. Perhaps your weapon is modular and the player can attach a scope component during gameplay.

The difference, if any, will be negligable unless you actively start looking for trouble.

  • interface calls are the slowest (but oh so convenient); they do not deserve demonising, though
  • then casting (annoying but necessary, even plain useful at times)
  • dispatchers can become convoluted but are exceptionally flexible and blazing fast - mostly due to the fact that, once registered, we no longer need to loop anything to send data to a bunch of listening entities. And the so called auto-bind (3rd pic in the original post) is actually pretty neat.

I’d choose what seems most transparent / logical to you. The thing is that you will end up using all forms of comms as soon as the project grows a bit in complexity. Seeing how you mention inheritance, it already has.

Sounds like it’s enough. But you need to have the comp talk to the weapon actor, ofc. The first 3 pics demonstrate the two most common methods. Namely:

The character BP does the line trace and calls an interface, the interface executes the logic in the Actor Component

A component receives an interface message and executes some logic:

It then calls a dispatcher :point_up: , whose call will be heard in the weapon actor :point_down: :

That’s pretty much it. No need to cast, look anything up, no need to employ another interface and it also works with inheritance - both the actors’ and the components’.

Nice, thanks.

One more thing, for many objects that share the same mechanism, would it be better to just use an interface between character BP and a master actor blueprint (such as master_weapon), add the logic there and make the individual weapons inherit from it without using a component?

Or would it be better to not make a master weapon BP and instead just add the component to each individual weapon?