Call a blueprint function that is overloaded?

As the title says, In C++ if I make a function that is overloaded for example…

public:
            UFUNCTION()
		void SetWidgetObjects(UUInventoryWidget* invWidget);

            UFUNCTION()
		void SetWidgetObjects(UUItemWidget* itemWidget);

Is there a way to call either one in a blueprint? Or is overloading not supported in Blueprint macros at the moment?

1 Like

Hi there, were you able to get an answer to this looking elsewhere?

Overloading is not supported for Blueprint functions, because function calls are resolved by name only and do not take the parameter list into account. If you attempt to overload it, UBT will print an error of the form:

‘MyFunction’ conflicts with ‘Function /Script/MyModule.MyClass:MyFunction’

See also: Overloading interface functions - UI - Epic Developer Community Forums

Is this something that might get added in the future?

If they are resolved by name, maybe the ‘signature’ can be included in the name?

2 Likes

Hey there,

you can do something like this:

//BlueprintLibrary.h:

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Function Name", Keywords = "Function Keywords"), Category = "Functions")
		bool Function(int32 Foo, TArray<FVector2D> Bar = {{-1,-1}});

//BlueprintLibrary.cpp:

bool BlueprintLibrary::Function(int32 Foo, TArray<FVector2D> Bar)
{
	switch (Bar.Contains(FVector2D(-1,-1)))
	{
	case true: return CppLibrary->Function(Foo);
		break;
	case false: return CppLibrary->Function(Foo, Bar);
		break;
	}
}

I know it is not exactly overloading… but it is a cheap workaround.

hope this helps.

quick edit: I gave the example of an array, but an array can not have a default value. In any other case like below it would be possible:

//BlueprintLibrary.h:

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Function Name", Keywords = "Function Keywords"), Category = "Functions")
		bool Function(int32 Foo, int32 Bar = -1);

//BlueprintLibrary.cpp:

bool BlueprintLibrary::Function(int32 Foo, int32 Bar)
{
	switch (Bar == -1)
	{
	case true: return CppLibrary->Function(Foo);
		break;
	case false: return CppLibrary->Function(Foo, Bar);
		break;
	}
}