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"

Creating a Widget in just C++

Hi I am trying to make a puzzle game where you need to enter a password into a textbox to open a door. I saw a load of examples online using blueprint but I want to try doing it with just c++ alone but can not find much learning resources online other then some old stuff from a couple of years ago.

I am currently using c++ in my project to open doors and activate triggers and the only decent resource I have found is this https://docs.unrealengine.com/latest/INT/API/Runtime/UMG/Components/UEditableTextBox/

I just want to note widgets are new to me I have not used them yet in my use of unreal as I am still learning it and what I am making is my first proper project.

So I am writing here to get the most relevant information possible on C++ and widgets and hopefully access to some helpful guides on the subject that I could learn from.

Product Version: UE 4.18
Tags:
more ▼

asked Feb 23 '18 at 07:17 PM in C++ Programming

avatar image

HitmanRm95
12 2 4 7

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

3 answers: sort voted first

Hello,

I would recommend looking into using the UUserWidget class for creating and maintaining Widget Blueprints in C++. Hope this helps.

Thanks, Daniel

more ▼

answered Feb 27 '18 at 04:40 PM

avatar image

Daniel U ♦♦ STAFF
210 2 5 3

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

There is a way to have your entire widget logic in C++ and only use BP for its design.

Make a C++ class which derives from UUserWidget, simply UserWidget in the create a class selector. Make a new BP widget and in the class settings make it use your custom class as its parent.

You can create the widget with the way Cd1232 mentioned and then make a variable for each type that you need to have logic for (Text Blocks, Scroll Boxes etc) and use the UPROPERTY() specifier meta = (BindWidget) to bind the visual element that you want to handle in C++.

To bind certain delegates for your variables like Click events for buttons, you need to override the initialize method:

 bool Initialize() override;

and in there bind your delegates like so:

 bool UYourClass::Initialize()
 {
     bool Success = Super::Initialize();
         if (!Success) { return false; }
     
         if (YourCustomButtonCreatedInHeader)
         {
             YourCustomButtonCreatedInHeader->OnClicked.AddDynamic(this, &UYourClass::OnClickedCustomButton);
         }
         return true;
 }

And then have the on clicked logic on your custom OnClickedCustomButton() function.

Making the graphics in C++ is the old way of making UI which I strongly advise against as it is a lot of extra work for nothing.

more ▼

answered Feb 23 '18 at 08:53 PM

avatar image

Balgy
95 3 8 11

avatar image HitmanRm95 Feb 25 '18 at 06:53 PM

Hi thanks for the information I tried creating the c++ class deriving from "UserWidget" as you recommended but it generated errors when I tried compiling and the class will not show up in my content browser till I compile it but when I do try and compile it same errors pop up again. Any idea why I might be getting these. I also ended up creating two c++ classes under "UserWidget" and they are both listed here.

Errors:

alt text

avatar image Balgy Feb 25 '18 at 06:58 PM

Linker errors are usually created when you are missing an include. In this case, I assume you need to add the UMG module in your build file.

Find your YourProject.Build.cs file and add "UMG" with the quotation marks in the Public Dependency Modules, like so:

 PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "UMG"});
avatar image HitmanRm95 Feb 26 '18 at 10:26 PM

Ya I tried it and still got errors, I tried starting a new project from scratch just see if UserWidget would work if I started a new project (to keep it separate from the other stuff I did) but the class still will not compile into unreal.

What I did was:

  1. Started a new project

  2. made changes to the .build.cs file you recommended (tried compiling afterwards and got errors)

  3. created widget ui design using BP

  4. create a custom c++ class with UserWidget in the create a class selector. (errors still pop up on compile)

I feel like I am likely missing a step here or doing something wrong. I might try it all again. Sorry for the inquiry I am likely making some rookie mistake somewhere.

avatar image Balgy Feb 27 '18 at 12:57 PM

Sorry, didn't quite catch that. Are you getting errors after adding the UMG module in the dependences or is it successfully added but you are still unable to compile a UUserWidget child?

avatar image HitmanRm95 Mar 04 '18 at 11:18 AM

Hi I started a serparate project as I ended up getting crashes so I did everything in a new project

First I added the UMG module in the build.cs file as you recommended alt text

I then compiled and got the following

alt text

I ignored the errors and tried to create a c++ class using userwidget and got the following response which would not allow the c++ class appear in the editor.

alt text

followed by the following in the error log

alt text

I also tried making a basic c++ class with some includes I was recommended elsewhere.

avatar image Balgy Mar 04 '18 at 11:22 AM

Well, the error log is quite specific actually. This doesn't have to do with the UMG module or your efforts to make a UUserWidget class. Your code doesn't compile elsewhere. More specific, in line 24 of your MyPlayerController.h where I assume you have misspelled "Category" as "Cathegory" in your UPROPERTY() specifiers.

avatar image HitmanRm95 Mar 04 '18 at 10:46 PM

After looking around and checking hereI got the build file to compile by adding "slate" and "slate core" modules with "UMG" in the build.cs file followed by adding a set of includes to the main project header file.

Now I have to just get password input setup thanks for the help.

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

This is how I managed to spawn a UMG widget through code

https://answers.unrealengine.com/questions/756759/unable-to-create-widget-no-outer-provided.html

I created the widget in the editor and then used FClassFinder to grab that class, and then spawned it using CreateWidget.

more ▼

answered Feb 23 '18 at 08:44 PM

avatar image

Cd1232
10 7 8 10

(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