Why does function declaration with the same name with different number of argument cause a build error?

Hi,

Let say that I want to do in my header file:

UFUNCTION()
FStringAssetReference getDefaultPawn(EName::Type Name);

UFUNCTION()
FStringAssetReference getDefaultPawn(EName::Type Name, uint8 Level);

Here is the error that I have:

1>...MyTest.h(19): error : In MyTest: 'getDefaultPawn' conflicts with 'Function /Script/MyGame.MyTest:getDefaultPawn'

I’m not an expert in C++, but I can’t see what’s wrong in those function definition. They don’t have the same number of parameters. Is it a UE constraint?

Thanks,

#No Overloads of UFUNCTION()s

I’m pretty sure you can’t overload UFUNCTION() :slight_smile:

If you dont need the UFUNCTION() for any network-code related reason, or for keybinding, I’d just take the UFUNCTION() out and do regular c++ overloading :slight_smile:

Rama

Take a look at thhis file comming with the engine source:

/UE4/UnrealEngine/Engine/Source/Programs/UnrealHeaderTool/Private/HeaderParser.cpp

1858: FError::Throwf(TEXT(“‘%s’ conflicts with ‘%s’”), *ThisName.ToString(), *It->GetFullName() );

The HeaderParser iterates trough all known function names before adding a new function to the unreal functions list, throwing this if there is one with the same name, no matter what the parameters are.

So it is not possible to have two UFUNCTIONS with the same name in the same class.


But you can still go the way I prefer and do this:

    UFUNCTION()
    FStringAssetReference getDefaultPawn(EName::Type Name);
     
    UFUNCTION()
    FStringAssetReference getDefaultPawnWithLevel(EName::Type Name, uint8 Level);

Thats much more literate on the calling side if you do a call like

myObj->getDefaultPawnWithLevel(SOMETHING, 5);

No need to indicate that 5 is meant as level here.

Thanks for the clarification and confirmation of Rama explanation.