Interface methods with same name as class methods

Hey all,

I’ve been using interfaces with increasing frequency as a way to reduce dependency and downcasting, and although there are definitely some quirks and limitations you have to keep in mind if you want them exposed to BP, I think they work pretty well for the most part.

However I’ve run into a small issue in regards to method naming with interfaces - here’s the context:

I have an interface, IPlayerDataProvider. It contains accessors for all kinds of player-related data and can realistically go on anything that relates to a specific player. Pawns, abilities, items, targeting actors, whatever.

All methods are BlueprintNativeEvent, and BlueprintCallable so that they can be implemented and called from BP.
Many methods have default implementations in the interface’s .cpp, and some default implementations call other methods in the same interface.

But if I implement

AController* IPlayerDataProvider::GetController()

method on my Character, the Unreal Header Tool seems to get real confused with the one on the base Pawn class when compiling.

Implementation of function 'Pawn::GetController' must be declared as 'event' to match declaration in interface 'PlayerDataProvider'

Now obviously I don’t want to mess with the one on Pawn, but I do want both to coexist the same way you can inherit from 2 interfaces that share method names in vanilla c++.

What’s the workaround here? Renaming a method on the interface because something can’t implement it seems a little bit backward.
It would be a real shame if we had to predictively avoid naming methods the same as any other method on every class and parent class of anything you might ever want to implement the interface on.

Both Interface and derived class must declare the Interface’s UFunction with the same UFUNCTION(…) param.
If you already do that, your problem may be because you don’t use any prefix and also use generic words to declare your C++ functions which may confuse UBT sometimes.

Most of my implementations work fine just overriding the **_Implementation **of a BlueprintNativeEvent declared on the interface, with no UFUNCTION needed on the derived class.


    UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
    AController* GetController() const; 
    virtual AController* GetController_Implementation() const;

**Derived Class:**
    virtual AController* GetController_Implementation() const override;

The issue is specifically trying to implement said interface on a class that already inherits a GetController() method from Pawn, and it seems to be because UBT assumes that no 2 inherited classes should ever have methods with the same name or signature.

Is it recommended to use prefixes on interface methods to avoid such situations?

1 Like