I implemented a code to call interface in C++. The interface is implemented both BP and C++. I wrote like below and it works well. Are there any problems with this way? Is there any better code?
bool CallTest(AActor* Target, FParamA& A, const FParamB& B)
{
if (Target->Implements<UTestInterface>()) // Call Blueprint interface if implemented in BP.
{
return ITestInterface::Execute_Test(Target, A, B);
}
else if (ITestInterface* Interface = Cast<ITestInterface>(Target)) // Else call C++ interface if implemented in C++.
{
return Interface->Execute_Test(Target, A, B);
}
return false;
}
all good. actually being curious and asking/researching when in doubt helps you learn faster and deeper.
(though i’d be cautious of answers that might be dogmatic)