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);
}