Hi there guys, here’s the problem.
I have an interface created like this.
UINTERFACE()
class MYPROJECT_API UInteractableInterface : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class MYPROJECT_API IInteractableInterface
{
GENERATED_IINTERFACE_BODY()
public:
UFUNCTION(BlueprintNativeEvent)
void Interact();
UFUNCTION(BlueprintNativeEvent)
void OnStartFocus();
UFUNCTION(BlueprintNativeEvent)
void OnEndFocus();
};
This work and i can implement the interface in blueprints. The problem comes when i try to cast a blueprint that implemented the interface.
if (GetWorld()->LineTraceSingleByChannel(outHit, start, end, ECC_Pawn, collisionQueryParams))
{
TArray<AActor*> overlapingActors;
GetPawn()->GetOverlappingActors(overlapingActors);
bool isInteractable = outHit.GetActor()->Implements<UInteractableInterface>();
bool focusedObjectIsOverlaping = overlapingActors.Contains(outHit.GetActor());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, isInteractable ? "YES" : "NO");
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Blue, outHit.GetActor()->GetName());
if (isInteractable && focusedObjectIsOverlaping)
{
IInteractableInterface *focusActor = Cast<IInteractableInterface>(outHit.GetActor());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, focusActor != nullptr ? "CASTED" : "CAST FAILED");
if (this->_interactableTarget != focusActor)
{
//End focus if another object was being focused
//if(this->_interactableTarget != nullptr)
// this->_interactableTarget->OnEndFocus();
//focusActor->OnStartFocus();
//Set the new interactable target and it's editor counterpart
//this->_interactableTarget = focusActor;
//this->InteractableTarget = focusActor;
}
}
}
Here… the outHit.GetActor() has an object that implements the interface VIA BLUEPRINT…
When i use the method Implements, it returns true, but when casting to IInterface fails, i read that this is because the Blueprint class has no c++ header information…
So my question would be.
How do i resolve this issue?
If i get to cast to the interface… how do i expose that IInterface variable to the Blueprint Editor? UPROPERTY seems to fail everytime (won’t let me compile)
Greetings!