Hi guys,
I have an interface (Unreal interface) called IInteraction. From this, is derived another Interface (cpp interface) called IPickable. And then I have a BasePickup which is child from an AActor and IPickable. So, in theory, BasePickup is also a IInteraction.
Now, in another part of the code, I have a delegate to OnComponentBeginOverlap, where I am receiving the AActor that has been collided. I want to work with IInteraction interface because I want to register this IInteractions collisions into a vector of IInteractions, regardless the specific type. So, I can work with pickups, or with some other kind of interactuable objects.
But here it comes the problem. Once I receive the colliding AActor, and I try to upcast to IInteraction, it always returns nullptr. It happens the same if I cast to IPickable.
I attach some code snippets:
IInteraction interface:
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "Interaction.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UInteraction : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class TERROR_API IInteraction
{
GENERATED_BODY()
};
IPickable interface
class TERROR_API IPickable : public IInteraction
{
public:
virtual void Pickup() = 0;
virtual UPickableData* GetData() = 0;
};
BasePickup
#pragma once
#include "Pickable.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "BasePickup.generated.h"
UCLASS(Abstract)
class TERROR_API ABasePickup : public AActor, public IPickable
{
GENERATED_BODY()
public:
ABasePickup();
public:
UPickableData* GetData() override;
virtual void Pickup() override {};
Some other place:
void AMainCharacter::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
IInteraction* interactionTriggered = Cast<IInteraction>(OtherActor);
if (interactionTriggered != nullptr)
{
mActionZone.AddInteractionObject(interactionTriggered);
}
}