0

I have experienced a strange issue writing the constructor of UUserWidget-inherited class. The problem appears only (checked in several other) in this class. Code: .h .cpp UserWidget.h CompilingResult

Sheim
  • 33
  • 9

2 Answers2

4

Try to add this to your base class (UUserWidget):

UUserWidget();

That's because there is no default constructor for this class. The default constructor is one which takes no parameters.

  • There already is a constructor `UUserWidget(const FObjectInitializer &ObjectInitializer);` why might it not be a default constructor? – Sheim Jan 20 '18 at 18:44
  • 2
    Because the default constructor does not take any parameters, so UUserWidget(const FObjectInitializer &ObjectInitializer); can't be a default constructor. – DankMemesBot Jan 20 '18 at 19:00
  • Similar result as with the previous constructor (I still don't know how might it help me - overloading shouldn't work in this case?) – Sheim Jan 20 '18 at 19:08
  • 1
    Are you sure?, I'm almost sure that this is what causing your problem... Your UUserWidget class should be like: public: UUserWidget(); and then UUserWidget(const FObjectInitializer &ObjectInitializer); – DankMemesBot Jan 20 '18 at 19:24
  • I think that i did it wrong last time. Now there is still a compilation problem, but different: [Result](https://prnt.sc/i37o8j) [UserWidget.h](https://prnt.sc/i37o8j) – Sheim Jan 20 '18 at 19:50
  • 2
    You've got a linkage error, most of them caused from including the classes incorrectly, this isn't about the constructors anymore. – DankMemesBot Jan 20 '18 at 19:57
  • Ok I have solved the issue. [.cpp](http://prntscr.com/i38hbc) Nothing else was needed. Thanks for your suggestions! – Sheim Jan 20 '18 at 20:45
  • 1
    @Sheim This is more of a specific Unreal Engine issue. You don't want to be adding code to the engine (as stated before). Essentially the difference is, If you look at Actor for example, it has a default () constructor. Whereas the UUserWidget does not. So you will need to just ensure you use the FObjectInitializer constructor instead. Should do the same job. Perhaps this is an oversight of Unreal Engine during their upgrade to allowing empty constructors. ```MyWidget::Mywidget(const FObjectInitializer& ObjectInitializer) : UUserWidget(ObjectInitializer){``` – Jimmyt1988 Dec 20 '19 at 16:20
2

add default constructor "UUserWidget();"