Access BlueprintImplementableEvent from Widget Blueprint

I have events defined in the GameMode C++ Class that are visible in the GameMode Blueprint Class via the GameMode::EventGraph. However, I cannot see the events in Widget Blueprint derived widgets. Is there a way to add an event subscriber in a Widget Blueprint?

Thank you.

The behavior of BlueprintImplementableEvents isn’t different for widget blueprints than other blueprints. Can you tell us what you’re trying to achieve?

BlueprintImplementableEvent allows you to execute blueprint logic by calling a function in C++. Is your goal here to trigger some events on external widgets as a result of calling a BlueprintImplementableEvent on your game mode? If so, you could create an EventDispatcher in your GameMode blueprint, call that one in your GameMode blueprint implementable event and make the widgets bind events to that event dispatcher.

Thank you for the help NisshokuZK.

Actually I’d like to achieve three items:

ITEM 1.
Trigger an event externally in a C++ source file and have the event listener in Widget Blueprint. I am able to create an event in the GameMode source files, and can listen for the event in the GameMode Blueprint Class. For example:



    .h

    UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "EnemyAttacked"))
    virtual void EnemyAttacked(int32 count);

    .cpp

    void AReallyGoodGameMode::Tick(float DeltaSeconds)
    {
        :
        :
        EnemyAttacked(6);
    }


When the above event is triggered I can act on it in the GameMode Blueprint Class because it is the only place that it appears visible. I cannot add an event listener in another Widget Blueprint. Is it possible to do this? It appears based on your response above that the GameMode Blueprint Class needs to be the arbiter of the event, and the other widgets need to listen to it. Do you have a documentation link that shows this that I can view? I’ll keep reading through the Blueprint documentation anyway.

ITEM 2.
Is there a way to BIND Widget Blueprint elements to a C++ Class? Specifically, can I bind UI elements such as TextBlock, EditableText to data members in a C++ class?

ITEM 3.
Is it possible to interface with the Editable Controls from C++? For example, get the current insert position, pass a character to be inserted in the edit control? A virtual keyboard basically.

Thank you again.

I don’t know the answer to Item 3, as for the others…

ITEM 1: I think a multicast delegate is what you want here. Note that BlueprintImplementableEvents can be best seen as virtual functions as opposed to actual event dispatchers. You declare a function in C++, but you implement or override the function body in blueprint. What you want is an event dispatcher that anyone can subscribe to right? If so, look into UE4 delegates. You can create a BlueprintAssignable multicast delegate in C++ like this:

In MyActor.h:




DECLARE_DYNAMIC_MULTICAST_DELEGATE( FMyEventSignature );

UCLASS()
class AMyActor : public AActor
{
....

   UPROPERTY(BlueprintAssignable)
   FMyEventSignature MyEventDispatcher;
}




In any function in MyActor.cpp:



    MyEventDispatcher.Broadcast();


So what this setup does is, whenever is called any event bound to it is fired. For events with parameters, look up more info about multicast delegates. The cool thing is, by making it blueprint assignable you can bind blueprint events to it by calling dragging a pin off MyActor and choosing “Assign to MyEventDispatcher” or “Bind Event to MyEventDispatcher”. Here is a snapshot from my project where I declared a delegate in C++ called OnTeamChange and bind a blueprint event to it from a widget.

events.png

ITEM 2: Definitely! If your widget blueprint has a variable of a UCLASS type, like a pointer to an actor or actor component and that class has UPROPERTIES that are blueprint accessible (BlueprintReadOnly or BlueprintReadWrite), then you can bind them to widget elements. For example if you have a variable of type MyActor and MyActor has a blueprint accessible float UPROPERTY, then you can bind that to say, the Percent value of a ProgressBar widget element.

Yes, I use UPROPERTY() now but the scope is limited to GameMode. In order to access the property in a Widget Blueprint I have to cast to the game mode. Is there a way to access the properties from a Widget Blueprint?

You can create a C++ class derived from Widget Blueprint but I don’t see how to tie the newly created class to a Widget Blueprint. Is this possible? It doesn’t make sense to have everything passing through either the Level Blueprint or the GameMode Blueprint.

Is there a one-to-one correspondence between C++ Widget Blueprint and Blueprint Graph Editor?