Function only compiles when passing FText by ref?

So I’m trying to pass these 2 FText vars and it will only let me pass by reference when I want to pass by value. Why is unreal generating const for these variables?

Current BaseElementWidget.h



UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Elements")
UUserWidget* AddButton(UBaseElementWidget* &Menu, FName ID, const FText &Caption, const FText &Tooltip);


Desired BaseElementWidget.h



UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Elements")
UUserWidget* AddButton(UBaseElementWidget* &Menu, FName ID, FText Caption, FText Tooltip);


Error


1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: PluginDev, Configuration: Development_Editor x64 ------
2>  Creating makefile for hot reloading PluginDevEditor (working set of source files changed)
2>  Compiling game modules for hot reload
2>  Performing 3 actions (4 in parallel)
2>  PluginDev.generated.cpp
2>  BaseElementWidget.cpp
2>D:\Documents\Unreal Projects\PluginDev\Intermediate\Build\Win64\UE4Editor\Inc\PluginDev\PluginDev.generated.cpp(103): error C2511: 'UUserWidget *UBaseElementWidget::AddButton(UBaseElementWidget *&,FName,const FText &,const FText &)': overloaded member function not found in 'UBaseElementWidget'
2>  D:\Documents\Unreal Projects\PluginDev\Intermediate\Build\Win64\UE4Editor\Inc\PluginDev\MenuEventHandler.generated.h(11): note: see declaration of 'UBaseElementWidget'
2>D:\Documents\Unreal Projects\PluginDev\Intermediate\Build\Win64\UE4Editor\Inc\PluginDev\PluginDev.generated.cpp(109): error C2352: 'UObject::FindFunctionChecked': illegal call of non-static member function
2>  d:\programfiles\epic games\4.13\engine\source\runtime\coreuobject\public\uobject\UObject.h(745): note: see declaration of 'UObject::FindFunctionChecked'
2>D:\Documents\Unreal Projects\PluginDev\Source\PluginDev\MUI\Private\BaseElementWidget.cpp(63): error C2511: 'UUserWidget *UBaseElementWidget::AddButton_Implementation(UBaseElementWidget *&,FName,FText,FText)': overloaded member function not found in 'UBaseElementWidget'
2>  D:\Documents\Unreal Projects\PluginDev\Intermediate\Build\Win64\UE4Editor\Inc\PluginDev\MenuEventHandler.generated.h(11): note: see declaration of 'UBaseElementWidget'
2>ERROR : UBT error : Failed to produce item: D:\Documents\Unreal Projects\PluginDev\Binaries\Win64\UE4Editor-PluginDev-2187.dll
2>  Total build time: 6.75 seconds
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3075: The command ""D:\ProgramFiles\Epic Games\4.13\Engine\Build\BatchFiles\Build.bat" PluginDevEditor Win64 Development "D:\Documents\Unreal Projects\PluginDev\PluginDev.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Basically I want to pass the FText by value like the bottom function but am being forced to pass by ref with the top function…
Untitled.png

Have you tried a non const reference? FText is support in Blueprints as a literal, so I don’t think copy by value is allowed due to localization resource gathering.

I had a similar problem with TArray: from here, the .generated header seems to convert the TArray pass-by-value parameter in a reference, generating a mismatch between .h and .cpp signature. In this case it seems that using const references is the standard way to deal with input parameters.
Anyway, passing a const reference won’t cause any sort of problem (it’s not like passing a pointer, you can use the variable without dereferencing) and it also avoids copying the whole object when passing a struct or class (Like FText or TArray).

Non const references are interpreted as output variables in blueprint

You can add UPARAM(ref) to make it an input pin. While it won’t be an output pin anymore, any changes made within the function will still be visible after calling it.

It appears it’s a problem with both BlueprintImplementableEvent and BlueprintNativeEvent. Could this be a bug?

It also appears to only error when passing a FText, although I haven’t had problems with TArrays but I normally pass by ref with them anyways.

You have to add meta=(AutoCreateRefTerm=“TextVarName”) to the UFUNCTION declaration, and declare the param as const FText& TextVarName. Then it will show up with an edit box.

5 Likes