Interface Usage

So somehow, I’ve only really started using Custom Events and Event Dispatchers recently. Game Changer! That being said the real shortcoming I’ve found is that they only work on that BP. I’ve been using Interfaces purely as a means to pass variables but would I be correct in my new assumption that the real power comes from basically allowing you to have Event Dispatchers that can notify other BPs?

1 Like

Aye, the power comes from the fact that you do not need a reference once they’ve been registered. You can register now, Once, pay the price and keep calling later for free.

Sending an interface message to 100k actors is very expensive. Dispatching is cheap and you no longer need a reference.

the real shortcoming I’ve found is that they only work on that BP.

Nah, you can register from any actor to any other actor - one of the most powerful features. And it does not need to be an actor, it can be a widget → component communication.

You often end up with managing classes that bind unrelated actors without those actors ever knowing that the other one exists; +1 for decoupling.

  • actor component in some actor:

  • actor component in another actor:

image

  • the actor component A can now talk (call a dispatcher) to B:

And if after 30 minutes of gameplay one of the actors gets destroyed… nothing will happen.


Another example:

I have 400 trees in the scene, I need the player controller to know when 3 very specific trees get chopped down:


You will need / use all 3 methods of comms anyway + inheritance. Choose the best tool for the job at hand.

1 Like

How do I go about accessing them in a different BP? Here is my current setup…

This is BPa where the original dispatcher was created. The Print String works.

This is BPb which most likely is incorrect but its where my head is at. The Print doesn’t fire. TurnBasedGameMode is where the orginal dispatcher is as well.

How do I go about accessing them in a different BP? Here is my current setup…

We need to know what it is, where it is and how the different BP actor makes into the game. You need to obtain a reference somehow.

This looks fine. How are you calling the dispatcher? In this example, the Game Mode has the dispatcher and talk to the actor we see.

My assumption was that the call start that makes the print string in BPa fire would fire off the bound event in BPb.

And you’re assuming correctly. So how does the Game Mode call it?

  • the game mode calls:

image

  • and every time it does, this actor will hear about it:

You could have 100 of actors like this, all will listen to the call.

Unless I’m missing something that’s essentially my same setup yet the print string on BPb does not fire for me.

Could you show how the GM calls it? What triggers the call?

BPa is TurnBasedGameMode and BPb is TurnBasedGameState

Should work fine unless you used Begin Play in the Game Mode - the Game State does not exist yet (or, to be more precise, has yet to register).

That’s why I keep asking how you’re calling it. :innocent:

1 Like

That’s it… GameState doesnt exist yet… would it work if i added a delay?

1 Like

Yes. 99% yes. It probably exist but has yet to fire its own begin play.