I want to use Interface in Actor on Scene to get value from another actor on scene. But when i use interface I cant get pointer to Actor. I use this on screenshot but this don t work.
You should look at the documentation regarding interfaces. You aren’t using the correct syntax for them
This is what the syntax should resemble:
if (MyActor->GetClass()->ImplementsInterface(UBinaryFruit::StaticClass())) {
IBinaryFruit::Execute_MYINTERFACEFUNCTION(MyActor);
// you can pass in other parameters that are in the interface function definition
}
// where MyActor is the class that implements the interface.
// MYINTERFACEFUNCTION is a function that is defined inside of the interface and is implemented in the class MyActor
if your interface function has parameters then pass them after the first parameter
The execute_ function takes the first parameter as the object the execute is run on, then the following parameters need to be like the interface function takes in
But APanalRandom not pointer to actor like interaction interface where you get a OutHit.GetActor.
How i can get a Actor with out hitting object? I cant understand
Anyway we were going off topic. Here is the main function
Though it used to be enough to call exec_ now it seems the pure c++ needs a cast and calling implementation
#include "InterfaceCaller.h"
#include "Interfaces/IBinaryFruit.h"
#include "PanelRandom.h"
#include "Interfaces/IInteractable.h"
AInterfaceCaller::AInterfaceCaller()
{
PrimaryActorTick.bCanEverTick = true;
}
void AInterfaceCaller::BeginPlay()
{
Super::BeginPlay();
APanelRandom* PanelR = NewObject<APanelRandom>(GetWorld(), TEXT("PanelR"));
if (PanelR != nullptr) {
if (PanelR->GetClass()->ImplementsInterface(UBinaryFruit::StaticClass()))
{
// c++
if (IBinaryFruit* f = Cast<IBinaryFruit>(PanelR)) {
if (AActor* returnedActor = f->Get_Implementation()) {
if (IInteractable* inter = Cast<IInteractable>(returnedActor)) {
bool Interaced = inter->Interact_Implementation();
}
}
}
// blueprint (need overides implemented from within bp)
AActor* retrieved1 = IBinaryFruit::Execute_Get(PanelR);
if (AActor* retrieved = IBinaryFruit::Execute_Get(PanelR))
{
if (retrieved->GetClass()->ImplementsInterface(UInteractable::StaticClass()))
{
bool Interaced = IInteractable::Execute_Interact(retrieved);
}
}
}
}
}