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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How do I call a blueprint widget from C++

I have a HUD coded in C++ and a widget created in BP, how do I use the BP widget in my C++ HUD?

Product Version: Not Selected
Tags:
more ▼

asked Nov 01 '14 at 09:35 PM in C++ Programming

avatar image

muttstuffle
16 2 3 4

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

0 answers: sort voted first

Easiest way (by that i mean without hardcoded refrences to uassets) is to make

 TSubclassOf<UUserWidget> 

exposed blueprint property (Widget Blueprint is subclass of UUserWidget)https://docs.unrealengine.com/latest/INT/API/Runtime/UMG/Blueprint/UUserWidget/index.html) in your HUD, it will ofcorse be UClass* type in which you will need to spawn using UWidgetBlueprintLibrary::Create (https://docs.unrealengine.com/latest/INT/API/Runtime/UMG/Blueprint/UWidgetBlueprintLibrary/Create/index.htm) and then you can operate it as this function return pointer to it. Create HUD blueprint from you C++ HUD and then you can set any blueprint widget in property you made.

You will also need to extend UUserWidget class to make C++ accessable varables and events so your C++ code can cooperate with Blueprint code

l

more ▼

answered Nov 01 '14 at 10:18 PM

avatar image

Shadowriver
36.5k 930 169 1111

avatar image xlar8or Nov 03 '14 at 01:11 PM

Great post, i've been trying to figure out how to do this. I did this on my character:

 APlayerController * PlayerController = this->Controller->CastToPlayerController();
 
         UUserWidget * Widget = UWidgetBlueprintLibrary::Create(GetWorld(), WidgetType, PlayerController);
         UWidgetBlueprintLibrary::SetInputMode_UIOnly(PlayerController, Widget, true);
         Widget->AddToViewport();

Where WidgetType is:

 UPROPERTY(EditDefaultsOnly, Category = "Character")
     TSubclassOf< class UUserWidget > WidgetType;

But he giving errors:

 'Z_Construct_UClass_UUserWidget': identifier not found
 'UWidgetBlueprintLibrary' : is not a class or namespace name
 'Create': identifier not found

and so on. Do i have to include a header to use this?

avatar image xlar8or Nov 04 '14 at 11:01 AM

I added the UMG, Slate and Slate core module and put the includes and he now recognizes UUserWidget, but he's giving me linking errors on the UWidgetBlueprintLibrary methods i use (Create and SetInputMode_UIOnly). Any ideas why? Do i need to define something or add another module for him to work?

avatar image innogames Jan 13 '15 at 05:04 PM

Hi, It seems that UWidgetLayoutLibrary as well as UWidgetBlueprintLibrary are not part of the public API of the UMG Module. You can access their headers and use the type, but it will fail on Link time because the implementation is not available. I did a workaround and copied and modified the implementation of the one needed function of UWidgetLayoutLibrary in my own class. It's dirty, but at least it works. I'd be happy to know a better way anyway. In my case I needed the current Viewport Scale in C++ (as I move some functionality from Widget Blueprint into code)

ciao Matthias

avatar image Mingah Feb 22 '17 at 12:36 AM

Add this header:

 #include "Runtime/UMG/Public/Blueprint/WidgetLayoutLibrary.h"

Now you can instantiate it like:

 UWidgetLayoutLibrary* WidgetLayoutLibrary;
 WidgetLayoutLibrary = NewObject<UWidgetLayoutLibrary>(UWidgetLayoutLibrary::StaticClass());



(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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