How to listen to GameMode events

Hello,

In my game (single player quest) I store objectives in GameMode object. The same object has a function which completes the current objective and moves on to the next one. Let’s call this function CompleteObjective

Then I defined a delegate (event) in the same class:

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FObjectiveChangedEvent);

// here go some class declarations

public:
	UPROPERTY(BlueprintAssignable)
	FObjectiveChangedEvent OnObjectiveChange;

Then in the function CompleteObjective I dispatch the event:

void ABabaYagaGameModeBase::CompleteCurrentObjective()
{
	CurrentObjective++;
	OnObjectiveChange.Broadcast();
}

Now what I try to accomplish is to be able to listen to this event in a blueprint.
For instance, I have a level blueprint

242871-level-blueprint.png

I would expect, that whenever an objective changes “New Objective” string shows up on the screen. But that does not seem to work at all.

My question is if that is even possible to do what I want? Can I listen to gamemode events? How so?

p.s. My Full Level Blueprint is here:

Yes, it’s absolutely possible to do what you want and everything you’ve done looks OK to me. Are you sure that your cpp CompleteCurrentObjective method is ever called? It might be worth putting a breakpoint in there or writing out a log message to confirm that.

It’s been called - that’s for sure.

I know how dispatchers work
And I don’t think this is gonna fit here.

First, there is no ‘another’ blueprint where I could add an event dispatcher and in GameMode class I use C++ delegates. Second, even with even dispatchers it’s not possible. How would I know when to call event dispatcher? I again need to listen to some event from C++ class. The same situation.

In order to run code in a blueprint when an event is fired in another blueprint you need to use event dispatchers.

The basic setup is to add a dispatcher to the event you want other blueprints to be notified of (the event in your GameMode class), and then in the other blueprints create a new custom event named something like “OnGameModeObjectiveChanged” and attach the Dispatcher to it.

Read through this (and the 3 pages linked at the bottom) to get an idea how this works. It might seem fairly complex at first, but it’s not as bad as it looks =)

.unrealengine.com/en-us/Engine/Blueprints/UserGuide/EventDispatcher

Hope that helps!

I’ve just re-read your post and I mis-understood - I thought your blueprint was the GameMode blueprint, not the level blueprint.

Generally speaking when I work with events have have some manager create the event (in this case it’s your GameMode), then my cpp components / actors etc will bind themselves to that event through AddDynamic. If I want to expose this event in the blueprint for designers to extend the system, then I’ll also have a BlueprintAssignable event on the component / actor.

I’ve never actually tried to do this with level blueprints, nor have I ever bound events within Blueprints (only C++), so this is just the way I would try to approach it (warning: may be complete nonsense!): The GameMode event shouldn’t be BlueprintAssignable. You should instead bind to the dispatcher from within you’re level blueprint (i.e. you’re level blueprint is listening for GameMode.OnObjectiveChange, which will in turn call an event or method within the Level Blueprint). See .unrealengine.com/en-us/Engine/Blueprints/UserGuide/EventDispatcher/BindingAndUnbinding

Sorry if that doesn’t make sense, I’d test this but I’m not on a machine with UE4 installed at the moment.

Delegates ARE event dispatchers they just have different name. You can bind delegates as event dispatcher by placing BlueprintAssignable in delegate event property like this:

UPROPERTY(BlueprintAssignable)
FSomeDelegate SomeNameOfEvent;

Then you delegates becomes event dispatcher in blueprint and you can bind to it like you normally would and it will be called when you normally broadcast in to delegate in C++

There no other work around, implementable events only work inside the related class, if you want to listen to event from somewhere else you need to use delegate.

That totally makes sense! But it seems that is what I did - I created a delegate and added an annotation UPROPERTY(BlueprintAssignable). And I see it in my blueprint:

THe problem is that it does not work

Oh thanks - that really works. Now, I don’t understand why this:

does not work :frowning: What’s the point of having that choice of events on the right - they don’t make any sense.

Hi, you did everything right but the final part is to actually listen to the event by calling the bind function here’s my example (tested and working)

Well it’s a delegate, you probably can broadcast it from BP as well. Unlike you I don’t have access to it for some reason, if you want something similar you can add a BlueprintImplementableEvent like this:

UFUNCTION(BlueprintImplementableEvent)
    	void ObjectiveDone();

You don’t need to add the definition in the CPP, and just call it when the objective is completed, this is however only accessed by the game mode.