UFUNCTION causing build errors

I’m trying to create a function that can be overridden in blueprints, however any time I try to add the UFUNCTION prefix I get build errors.

ToolTipDesign.h

#pragma once

#include "Blueprint/UserWidget.h"
#include "ToolTipDesign.generated.h"

/**
 * 
 */
UCLASS()
class MYPROJECT_API UToolTipDesign : public UUserWidget
{
	GENERATED_BODY()
	
public:

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	FText MyToolTipText;

	virtual void NativeConstruct() override;

	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ToolTip")
	bool SetToolTipTextDesign(FText ToolTip);
};

ToolTipDesign.cpp

#include "MyProject.h"
#include "ToolTipDesign.h"

void UToolTipDesign::NativeConstruct()
{
	Super::NativeConstruct();

	SetToolTipTextDesign(MyToolTipText);
}

bool UToolTipDesign::SetToolTipTextDesign(FText ToolTip)
{

	return false;
}

The compile errors

Error C2511 ‘bool UToolTipDesign::SetToolTipTextDesign(const FText &)’: overloaded member function not found in ‘UToolTipDesign’

Error C2352 ‘UObject::FindFunctionChecked’: illegal call of non-static member function

When I remove “UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = “ToolTip”)” the build errors go away however I an unable to override the function in blueprints.

In your header add one line so it looks like this (i believe this is optional, but I like it better to explicitly declare it):

 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ToolTip")
 bool SetToolTipTextDesign(const FText& ToolTip);
 bool SetToolTipTextDesign_Implementation(const FText& ToolTip);

In your cpp change the implemented function name to SetToolTipTextDesign_Implementation:

 bool UToolTipDesign::SetToolTipTextDesign_Implementation(const FText& ToolTip)
 {
      return false;
 }

For BlueprintNativeEvent, and others, the UHT generates code that implements SetToolTipTextDesign (because it needs to call blueprint), which calls the SetToolTipTextDesign_Implementation that you need to implement.

edit:

I also changed the FText parameters to const FText& (as it is best practice in c++), because the UHT seems to enforce this, and does not allow the FText by copy parameter.

Note that const reference and copy are semantically the same, const ref is usually faster.

When I put this into the code I’m getting the same errors word for word.

Yes, you are right, you need to use const FText& ToolTip instead of FText ToolTip Seems that the UHT enforces this, which I did not know. Updating the answer.

It worked thank you.