Why am I getting a no default constructor exists for class error

Hi I’ve been trying to make a custom rich text decorator but I keep getting a no default constructor exists for class error and don’t known why?

Here’s code below
.h

class UNREALCOC_API FRichTextTooltipS : public FRichTextDecorator {

	GENERATED_BODY()

public:
	FRichTextTooltipS(const FObjectInitializer& ObjectInitializer);

	virtual bool Supports(const FTextRunParseResults& RunParseResult, const FString& Text) const override {

	};

	
};

UCLASS()
class UNREALCOC_API URichTextTooltip : public URichTextBlockDecorator {

	GENERATED_BODY()

public:
	

};

.cpp

FRichTextTooltipS::FRichTextTooltipS(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer) {


}

I found this but it didn’t help “no default constructor exists for class ”UUserWidget“”

Note: removing the super does not help.

I would appreciate any help

Because no default constructor exists. A default constructor is one that can be called with no parameters. You only have a constructor that can be called with an instance of an FObjectInitializer.

You have three options:

  1. remove the FObjectInitializer& from your FRichTextTooltipS constructor. You’re not dealing with an object, so you shouldn’t need an FObjectInitializer.
  2. create a second constructor that take 0 parameters.
  3. remove the USTRUCT and GENERATED body from your FRichTextrTooltipS structure. The FRichTextDecorator that you’re inheriting from doesn’t appear to be a USTRUCT so if you derive from it, it probably shouldn’t be one either.
1 Like

Hi MagForceSeven I’ve tried removing the parameters, super from FRichTextTooltipS and the generator body but I’m still getting the here the updated code

Note: I’m also not sure what you mean by removing USTRUCT? are you refereeing the F prefix because the class isn’t a struct or have struct generator body
.H

class FRichTextTooltipS : public FRichTextDecorator {

	

public:
	FRichTextTooltipS();


	virtual bool Supports(const FTextRunParseResults& RunParseResult, const FString& Text) const override {

	};

	
};

UCLASS()
class UNREALCOC_API URichTextTooltip : public URichTextBlockDecorator {

	GENERATED_BODY()

public:

	
};

.cpp

FRichTextTooltipS::FRichTextTooltipS()
{

}

here’s a error pic

Hi! Try with FRichTextTooltipS() = default; to discard issues.

My mistake, I thought you might have omitted it. It’s the only reason you should have had the GENERATED_BODY macro.

Okay, I think I know what the deal is. It’s because of how FRichTextDecorator is setup. You just don’t see a whole lot of “regular” C++ in the engine. The only constructor it provides takes a parameter so you’ll probably need to take that parameter.

This would be the cpp:

FRichTextTooltipS::FRichTextTooltipS( URichTextBlock *InOwner ) : FRichTextDecorator( InOwner )
{
}

and for the header you would just match that declaration. If you want to pass more parameters to your constructor you can. If you can get that InOwner from a custom parameter of your constructor you can. As long as you can pass a URichTextBlock* parameter to the FRichTextDecorator constructor.

Note: Super doesn’t work here because that’s powered by the GENERATED_BODY macro which (as this isn’t a USTRUCT) can’t be used so you’ve got to directly specify the parent type as normal (for C++ at least).