RPC function generate compilation errors ( unwanted const qualifier on a method)

On unreal engine 5.7, trying to implement an RPC method :

UFUNCTION(Server, Reliable)
void EquipItem(UInventoryItemInstance* Item) ;

with the implementation:

void UEquipmentManagerComponent::EquipItem_Implementation(UInventoryItemInstance* Item)
{

}

The compilation give me those errors:
EquipmentManagerComponent.gen.cpp(243, 34): [C2511] ‘void UEquipmentManagerComponent::EquipItem(UInventoryItemInstance *) const’: overloaded member function not found in ‘UEquipmentManagerComponent’

EquipmentManagerComponent.gen.cpp(247, 20): [C2352] ‘UObject::FindFunctionChecked’: a call of a non-static member function requires an object

EquipmentManagerComponent.cpp(228, 34): [C2511] ‘void UEquipmentManagerComponent::EquipItem_Implementation(UInventoryItemInstance *)’: overloaded member function not found in ‘UEquipmentManagerComponent’

The EquipmentManagerComponent.gen.cpp has a EquipItem method but with a const qualifier:

void UEquipmentManagerComponent::EquipItem(UInventoryItemInstance* Item) const
{
EquipmentManagerComponent_eventEquipItem_Parms Parms;
Parms.Item=Item;
UFunction* Func = FindFunctionChecked(NAME_UEquipmentManagerComponent_EquipItem);
const_cast<UEquipmentManagerComponent*>(this)->ProcessEvent(Func,&Parms);
}

What can prevent unreal to generate/glue properly the declaration and the rpc implementation?

i believe it shouldnt have the EquipItem method because you should be using the Implementation

Thats what the doc state about rpc: declare a method annotated with UFUNCTION(Server, (reliable/unreliable) and implements a function with the same name suffixed by _implementation

them the compilation process will generate the glue to call the implementation. Thats what I saw on a lot of examples

Agreed, so you need

void UEquipmentManagerComponent::EquipItem_Implementation(UInventoryItemInstance* Item) const

not

void UEquipmentManagerComponent::EquipItem(UInventoryItemInstance* Item) const

having both is likely what causes the error

The problem was that my component had a const qualifier in the UCLASS annotation UCLASS(…, …, const).

Once I removed it, it worked as expected

1 Like