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.
asked Feb 23 '18 at 07:17 PM in C++ Programming
I would recommend looking into using the UUserWidget class for creating and maintaining Widget Blueprints in C++. Hope this helps.
answered Feb 27 '18 at 04:40 PM
Daniel U ♦♦ STAFF
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:
and in there bind your delegates like so:
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.
This is how I managed to spawn a UMG widget through code
I created the widget in the editor and then used FClassFinder to grab that class, and then spawned it using CreateWidget.
answered Feb 23 '18 at 08:44 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here