Hi there guys, i’m making steady process.
Right now i’m crafting code on c++ and i found this issue. I created a new c++ interface (using Ramma’s explanation) on
I created a c++ interface called InteractableInterface wich has a UInteractableInterface and a IInteractableInterface.
The IInterface part looks like this.
class MYPROJECT_API IInteractableInterface
{
GENERATED_IINTERFACE_BODY()
public:
UFUNCTION(BlueprintNativeEvent)
void Interact();
UFUNCTION(BlueprintNativeEvent)
void OnStartFocus();
UFUNCTION(BlueprintNativeEvent)
void OnEndFocus();
};
This works excelent i can implement this interface on blueprints or on c++ classes with no trouble at all…
The problem comes when i need to trigger this actions. My PlayerController right now uses linecast to check if an actor using this interface is on focus,this works, using
bool isInteractable = UKismetSystemLibrary::DoesImplementInterface(outHit.GetActor(),UInteractableInterface::StaticClass());
My main idea was to store a reference for the Interactable Actor so the team can call it on blueprint or C++ code.
Here’s where i found the issue, how would i procede from here? casting the Actor to store it always return nulls per:
//Linecast result being cast to IInteractableInterface Fails
IInteractableInterface *focusActor = Cast(outHit.GetActor());
And even if it worked, i think i can’t show IInteractableInterface to Blueprints.
My question is… being a programmer and having experience using interfaces… how should i proceed? should i store this on an Actor reference only? does this implementation works if i implement the interface on C++ OR on blueprint? or do i have to use different use cases for each one?
Bye!