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. 

Launch a Blueprint Widget from C++ code

I am looking to launch a Blueprint Widget with a custom class (followed this tutorial) from my C++ code -- specifically when the player is facing an item, and presses a 'Use' key the Widget pops up -- but cannot seem to get this to work.

 void AProtagonist::Take(){
     if (GetItemFocus()){
        // Trigger an existing BP Widget
     }
 
 }

I have already Googled extensively for the answer (ie here and here seemed like the should work but didn't) and haven't been able to find something that works for me yet, any help would be greatly appreciated.

Product Version: UE 4.8
Tags:
more ▼

asked Jul 02 '15 at 09:35 PM in C++ Programming

avatar image

ThereExistsX
1 1 2 2

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

1 answer: sort voted first

Easiest and quite comftible to use (since it creates some soft of interface) way to for bidriectional BP and C++ communication, is to create C++ base class with things you want to have in C++ and then make blueprint that based of it

So create new class based of UUserWidget, put property variables for widgets you want to control, now create widget BP based of that class or change existing BP class in "Blueprint Settings". After that go to defaults of BP and set variables you made with widgets that you placed in that BP. Now you can get current user widget that is displayed in viewport and control widget in it via variables you made.

more ▼

answered Jul 02 '15 at 11:52 PM

avatar image

Shadowriver
36.6k 931 169 1111

avatar image ThereExistsX Jul 03 '15 at 12:34 AM

Okay, so, at this point I have most of that -- I have a UUserWidget called 'Examine' and a Blueprint based off that called 'NewWidgetBlueprint' what I want to do is set it so that when I press a key and trigger the above Take() method 'NewWidgetBlueprint' pops up. I'd rather keep that triggering in C++ (if possible) because the Take() method does a few other things.

I've been trying variations on this code in the Take method:

 FStringClassReference MyWidgetClassRef(TEXT("/Game/NewWidgetBlueprint.NewWidgetBlueprint"));
         UClass* MyWidgetClass = MyWidgetClassRef.TryLoadClass<UExamine>();
         UExamine *widget = CreateWidget<UExamine>(GetWorld()->GetFirstPlayerController(), MyWidgetClass);
         widget->AddToViewport();

But no joy so far. Any thoughts?

avatar image gibbsies Feb 14 '16 at 03:14 AM

I would like an answer to this as well. I am trying something like this:

UObject* something = StaticLoadObject(UObject::StaticClass(), nullptr, pathToBlueprint); UBlueprint* bp = Cast(something); TSubclassOf WidgetTemplate; WidgetTemplate = (UClass*)bp->GeneratedClass;

      // problem is,  TSubclassOf<class UObject>  and TSubclassOf<class UUWidget don't work together> 

     UCardWidget * Widget = dynamic_cast<UCardWidget*>(UWidgetBlueprintLibrary::Create(GetWorld(), WidgetTemplate, GetWorld()->GetFirstPlayerController()));
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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