Interface Adding a method's implementation causes issues

I’m trying to create an interface that I can use in both Blueprint and C++. It has two void methods in that interface: Pickup and Drop. I have an actor that inherits from the the interface(its named InteractablesInterface) called PickupActor(it is a static mesh actor). When I enter the Drop implementation method, it gives me an error saying that: "BlueprintImplementableEvents in Interfaces must not be declared ‘virtual’ " even though I’m using a BlueprintNativeEvent where it says the error is. I have been searching through forums and other answerhub questions involving setting up interfaces and I’m entirely stuck at this point. If there are any other errors that anybody see’s in my code please point them out because I’m trying to learn how to use interfaces and its been an uphill battle so far(yes I tried Rama’s wiki and the official documentation and yet I ended up here).

Interface.h

#pragma once

#include "InteractablesInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(Blueprintable)
class UInteractablesInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

/**
 * 
 */
class VIVETESTINGPROJECT_API IInteractablesInterface
{
	GENERATED_IINTERFACE_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	
	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pickup")
		virtual void Pickup(USceneComponent* AttachTo);
		
	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Drop")
		virtual void Drop();
		
};

Interface.cpp

#include "ViveTestingProject.h"
#include "InteractablesInterface.h"


// This function does not need to be modified.
UInteractablesInterface::UInteractablesInterface(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{

}

// Add default functionality here for any IInteractablesInterface functions that are not pure virtual.

void IInteractablesInterface::Pickup(USceneComponent* AttachTo)
{

}

void IInteractablesInterface::Drop()
{

}

PickupActor.h

#pragma once

#include "Engine/StaticMeshActor.h"
#include "InteractablesInterface.h"
#include "PickupActor.generated.h"

/**
 * 
 */
UCLASS()
class VIVETESTINGPROJECT_API APickupActor : public AStaticMeshActor, public IInteractablesInterface
{
	GENERATED_BODY()

public:

	virtual void Pickup_Implementation(USceneComponent* AttachTo) override;

	virtual	void Drop_Implementation() override;
	
};

PickupActor.cpp

#include "ViveTestingProject.h"
#include "PickupActor.h"

void APickupActor::Pickup_Implementation(USceneComponent* attachTo)
{
	GetStaticMeshComponent()->SetSimulatePhysics(false);
	GetRootComponent()->AttachToComponent(attachTo, FAttachmentTransformRules::KeepWorldTransform);
}

void APickupActor::Drop_Implementation()
{
	GetStaticMeshComponent()->SetSimulatePhysics(true);
	this->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
}

Hey Oldsiren,

At first sight everything looks good :slight_smile:

to fix the error just do what it says, it is really simple :slight_smile: delete the virtual in your interface:

class VIVETESTINGPROJECT_API IInteractablesInterface
 {
     GENERATED_IINTERFACE_BODY()
 
     // Add interface functions to this class. This is the class that will be inherited to implement this interface.
 public:
     
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pickup")
     void Pickup(USceneComponent* AttachTo);
         
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Drop")
     void Drop();
         
 };

If you have any other questions you can ask :slight_smile:

Hope this helps,
Elias

I appreciate the help very much!

I’m having another issue where I have another actor inheriting from the interface, and all I want to do in this class is just send messages rather than actually do stuff with that method/function. What would be a way of doing this?

Error:
“pure virtual function “IInteractablesInterface::Drop_Implementation” has no overrider”
“pure virtual function “IInteractablesInterface::Pickup_Implementation” has no overrider”

This is stopping the actor from Generating_Body()

I think the error means that you have to override Drop_Implementation() and Pickup_Implementation() in your actor because they are marked as pure virual.

I think if you put them in your IInteractablesInterface as virtual it will also solve the error.

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Drop")
void Drop();
virtual void Drop_Implementation() { };

If (actor->Implements())
{
IInteractablesInterface::Execute_Pickup(actor);
}

Like this I think, it should be explained in the docs tho :slight_smile:
You should only use the ‘Execute_’ if the function is an BP event, any other functions you can just use.

edit: Implements UInteractablesInterface

So I created the methods/functions in the other Actor class(which fixed the error), but how would I(if its possible) be able to call to the PickupActor’s methods/functions of Pickup and Drop from the other Actor class using the interface?

Similar to how Blueprint Interface’s can send a message and activate other methods/functions in other BP’s that use that same interface.

I tried that way of checking to see if it uses an interface and it didn’t work(the reason is because “IInteractablesInterface” isn’t a static class so Implements wouldn’t work with it, luckily the official documentation and the Rama tutorial’s both ways of checking are fine. Thank you very much! This has helped me immensely.