The task is to initiate the custom Event in the widget to refresh some variables.
I created a C++ class derived from the UUserWidget
#pragma once
// Includes from Engine
#include "Blueprint/UserWidget.h"
#include "ContainerWidgetUpdate.generated.h"
UCLASS()
class MYGAME_API UContainerWidgetUpdate : public UUserWidget
{
GENERATED_BODY()
public:
/* Update container widget in case of adding of removing some items */
UFUNCTION(BlueprintImplementableEvent, Category = "Container Widget Update Event")
void UpdateWidget();
};
Widget BP is derived from this class.
I found this event and used it in the BP. No any issues.
Next step is initiate this event from others C++ classes.
I tried todo next
#include "UI/ContainerWidgetUpdate.h"
And somewhere in the functions
Cast<UContainerWidgetUpdate>(UpdateWidget()); // does not work
Cast does not work. Probably I need to declare UContainerWidgetUpdate();
#pragma once
// Includes from Engine
#include "Blueprint/UserWidget.h"
#include "ContainerWidgetUpdate.generated.h"
UCLASS()
class MYGAME_API UContainerWidgetUpdate : public UUserWidget
{
GENERATED_BODY()
UContainerWidgetUpdate(); // it does not work!!! Is was added to ContainerWidgetUpdate.cpp also.
public:
/* Update container widget in case of adding of removing some items */
UFUNCTION(BlueprintImplementableEvent, Category = "Container Widget Update Event")
void UpdateWidget();
};
The question is how to cast to the UUserWidget class from other C++ classes.
May be this is a wrong approach.