x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Cast to UUserWidget class from C++

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.

Product Version: UE 4.17
Tags:
more ▼

asked Aug 31 '17 at 08:10 PM in C++ Programming

avatar image

SvarogZ
47 3 2 8

avatar image SvarogZ Sep 02 '17 at 10:13 AM

Approach was totally wrong.

How it should be:

  1. Widget Blueprint should be derived from standard UserWidget

  2. For updating data in the widget is better to use function in this blueprint.

  3. For initiation of this function and control all widgets there is UMG blueprint derived from custom C++ class

  4. Events should be in that C++ class (BlueprintImplementableEvent or BlueprintNativeEvent)

  5. Initialization of events through Player Controller using reliable client function with casting to UMG C++ class and calling the events.

  6. Player controller function can be cast from the others C++ classes.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question