Interface Error

Hi!

When trying to build the project the following error pops up:

PlayerInterface.gen.cpp(106): Error C2511 : void IPlayerInterface::Equip(USkeletalMesh *,EEquipmentID,const TArray<UMaterialInterface *,FDefaultAllocator> &): overloaded member function not found in "IPlayerInterface"
UINTERFACE(MinimalAPI, Blueprintable)
class UPlayerInterface : public UInterface
{
	GENERATED_BODY()
};
class ODWIRKSRPG_API IPlayerInterface
{
	GENERATED_BODY()

public:
        UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category="PlayerInterface | Equipment")
	void Equip(USkeletalMesh* EquipmentMesh, TEnumAsByte<EEquipmentID> EquipmentID,
	const TArray<UMaterialInterface*>& EquipmentMeshMaterials);
};

this is how I call it:

void AWearable::OnInteract(AMainCharacter* PlayerCharacter)
{
	Super::OnInteract(PlayerCharacter);

	if (IPlayerInterface* PlayerInterface = Cast<IPlayerInterface>(PlayerCharacter))
	{
		TArray<UMaterialInterface*> Materials = ItemMeshComponent->GetMaterials();
		PlayerInterface->Execute_Equip(
			PlayerCharacter,
			ItemMeshComponent->GetSkeletalMeshAsset(),
			EquipmentID, 
			Materials);
	}
}

What’s wrong ???

Thx.

I think the way you’re implementing the interface might need adjusting. I’m assuming you want to use this in blueprint too but C++ has no grantees you will do that so it needs the interface function implemented natively too.

Your UFUNCTION should be like this using the BlueprintNativeEvent instead.

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="PlayerInterface | Equipment")

In your character header you need to implement the interface using _Implementation. You still have the ability to override your interface in blueprint.

void Equip_Implementation(USkeletalMesh* EquipmentMesh, TEnumAsByte<EEquipmentID> EquipmentID,
 	const TArray<UMaterialInterface*>& EquipmentMeshMaterials) override;

You can either implement the function in C++ or if it’s purely for blueprint you can do it in header by ending it with empty { }

For using the interface I usually go with this

if (PlayerCharacter->Implements<UPlayerInterface >())
{
	IPlayerInterface::Execute_Equip(PlayerCharacter, ...);
}
//PlayerInterface.h
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="PlayerInterface | Equipment")
	void Equip(USkeletalMesh* EquipmentMesh, TEnumAsByte<EEquipmentID> EquipmentID,
	const TArray<UMaterialInterface*>& EquipmentMeshMaterials);
//MainCharacter.h
public:
virtual void Equip_Implementation(USkeletalMesh* EquipmentMesh, TEnumAsByte<EEquipmentID> EquipmentID, const TArray<UMaterialInterface*>& EquipmentMeshMaterials) override;
//MainCharacter.cpp
void AMainCharacter::Equip_Implementation(USkeletalMesh* EquipmentMesh, TEnumAsByte<EEquipmentID> EquipmentID,
	const TArray<UMaterialInterface*>& EquipmentMeshMaterials)
{
	IPlayerInterface::Equip_Implementation(EquipmentMesh, EquipmentID, EquipmentMeshMaterials);
}
...
if (PlayerCharacter->Implements<UPlayerInterface >())
	{
		IPlayerInterface::Execute_Equip(
			PlayerCharacter, 
			ItemMeshComponent->GetSkeletalMeshAsset(),
			EquipmentID,
			ItemMeshComponent->GetMaterials()
		);
	}
...

Console Logs:

11>MainCharacter.h(167): Error C3668 : AMainCharacter::Equip_Implementation: method with override specifier ‘override’ does not override any base class methods

11>MainCharacter.h(167): Warning C4263 : void AMainCharacter::Equip_Implementation(USkeletalMesh *,TEnumAsByte<EEquipmentID>,const TArray<UMaterialInterface *,FDefaultAllocator> &): member function does not override any virtual member function of the base class

11>MainCharacter.h(253): Warning C4264 : void IPlayerInterface::Equip_Implementation(USkeletalMesh *,EEquipmentID,const TArray<UMaterialInterface *,FDefaultAllocator> &): no available override for virtual member function from base class ‘IPlayerInterface’; function hidden

:grinning_face: :smiley: :grinning_face_with_smiling_eyes: :grin: :laughing: :sweat_smile: :rofl: :joy:

Do you have the interface added to your character class ? For example at the end of this

class AMainCharacter : public ACharacter, public IPlayerInterface

Also for your MainCharacter.cpp that’s where you handle equipping you don’t wanna call the same interface

//MainCharacter.cpp
void AMainCharacter::Equip_Implementation(USkeletalMesh* EquipmentMesh, TEnumAsByte<EEquipmentID> EquipmentID,
	const TArray<UMaterialInterface*>& EquipmentMeshMaterials)
{
	GetMesh()->.. //for example
}
class ODWIRKSRPG_API AMainCharacter : public ACharacter, public ISaveableInterface, public IPlayerInterface

The problem is that I don’t want to have an interface implementation in C++, but only in Blueprint

Gotcha. So tried doing the same thing and it seems like the EEquipmentID enum is creating some problem because without it the C++ compiles just fine even if no implementation exists. It also compiles fine if we don’t use the TEnumAsByte.

This works fine just doing EEquipmentID EquipmentID instead of TEnumAsByte, test it and see if your blueprint is able to set it just fine.

 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="PlayerInterface | Equipment")
	void Equip(class USkeletalMesh* EquipmentMesh, EEquipmentID EquipmentID, const TArray<UMaterialInterface*>& EquipmentMeshMaterials);

Also you can go back to your original code since the issue is not what I thought. BlueprintNativeEvent is needed in this case.

Thank you so much. :heart_on_fire:
I don’t know why I haven’t stopped using regular enums. :slightly_smiling_face:

1 Like