Hi,
I am trying to create an “Interaction” interface that is using RPCs. Browsing the forums and the Answer Hub, I think it should be possible, but I haven’t found an actual working example.
I have created an interface called “I_Interaction” with a “StartInteraction()” and a “StopInteraction()” function:
“I_Interaction.h”
#pragma once
#include "I_Interaction.generated.h"
UINTERFACE()
class MYGAME_API UI_Interaction : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class MYGAME_API II_Interaction
{
GENERATED_IINTERFACE_BODY()
//Interface Functions
UFUNCTION(Server, Reliable, WithValidation)
virtual void StartInteraction();
UFUNCTION(Server, Reliable, WithValidation)
virtual void StopInteraction();
};
“I_Interaction.cpp”
#include "MYGAME.h"
#include "I_Interaction.h"
//Constructor
UI_Interaction::UI_Interaction(const class FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)
{
}
I am implementing the interface in an AActor derived class called “EQ_Overlord”
“EQ_Overlord.h”
#pragma once
#include "Interface/I_Interaction.h"
#include "Entity/Entity_Overlord.h"
#include "EQ_Overlord.generated.h"
UCLASS(abstract)
class MYGAME_API AEQ_Overlord : public AEntity_Overlord, public II_Interaction
{
GENERATED_BODY()
//Declaring Constructor
public: AEQ_Overlord();
protected:
virtual void StartInteraction_Implementation() override;
virtual void StopInteraction_Implementation() override;
};
“EQ_Overlord.cpp”
#include "MYGAME.h"
#include "EQ_Overlord.h"
//Constructor
AEQ_Overlord::AEQ_Overlord() :Super()
{
}
//Interface Functions
bool AEQ_Overlord::StartInteraction_Validate()
{
return true;
}
void AEQ_Overlord::StartInteraction_Implementation()
{
}
bool AEQ_Overlord::StopInteraction_Validate()
{
return true;
}
void AEQ_Overlord::StopInteraction_Implementation()
{
}
I cannot compile this, I get the following errors:
error C2509: 'StartInteraction_Validate': member function not declared in 'AEQ_Overlord'
error C2509: 'StopInteraction_Validate': member function not declared in 'AEQ_Overlord'
Now what confuses me is that as far as I know, both an RPC and an Interface function should use an “_Implementation” suffix. How do I get around this? I have tried many other options, but I couldn’t even get it to compile.
Is even calling RPCs through an interface possible? If so, how? I hope someone can shine some light on this for me.
Thanks!