Function with same name than Ufunction

Hi,

I noticed that creating a function with the same name than an Ufunction of the base class, even with different signatures, confuses the compiler a lot.

As an example, the Primitive Component declares the following Ufunction:

UFUNCTION(BlueprintCallable, Category="Rendering|Material")
virtual void SetMaterial(int32 ElementIndex, class UMaterialInterface* Material);

Inheriting from it, I declare a function with the same name but different signature:

UCLASS()
class UFooMeshComponent : public UPrimitiveComponent
{
    GENERATED_UCLASS_BODY()
public:
    void SetMaterial( UMaterial* InMaterial );
};

I get the following compiler warnings:

FooMeshComponent.h(12): warning C4263: 'void UFooMeshComponent::SetMaterial(UMaterial *)' : member function does not override any base class virtual member function

FooMeshComponent.h(13): warning C4264: 'void UPrimitiveComponent::SetMaterial(int32,UMaterialInterface *)' : no override available for virtual member function from base 'UPrimitiveComponent'; function is hidden

Engine\Source\Runtime\Engine\Classes\Components/PrimitiveComponent.h(624) : see declaration of 'UPrimitiveComponent::SetMaterial'

Engine\Source\Runtime\Engine\Classes\Components/PrimitiveComponent.h(102) : see declaration of 'UPrimitiveComponent'

So different things confuse me here:

  • I know this is a poor choice of names anyway but why is that an issue at all to the compiler since the signatures are different? I’m not using “override” here. Is the compiler being somehow too smart? Or is it something with the additional code generated by UHT?
  • Could UHT catch this sort of mistakes earlier on, as it does with implementations of overridden interface functions?

#No OverLoading UFUNCTION

You can’t overload a UFUNCTION()

So use unique names :slight_smile:

Rama

PS: I dont know all the reasons why, but I dont think you are getting around this restriction any time soon

That’s still a weird behaviour. But okay, I understand there’s some magic involved. Thanks!