Follow the first two recipes so that you have a UInterface
we can check for, and a class implementing the interface, which can be tested against.
BeginPlay
function:FTransformSpawnLocation; ASingleInterfaceActor* SpawnedActor = GetWorld()->SpawnActor<ASingleInterfaceActor> (ASingleInterfaceActor::StaticClass(), SpawnLocation); if (SpawnedActor->GetClass()->ImplementsInterface(UMyInterface::StaticClass())) { GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, TEXT("Spawned actor implements interface!")); }
ASingleInterfaceActor
and IMyInterface
, we need to #include
both MyInterface.h
and SingleInterfaceActor.h
in our Source file.BeginPlay
, we create an empty FTransform
function, which has the default value of 0
for all translation and rotation components, so we don't need to explicitly set any of them.SpawnActor
function from UWorld
so that we can create an instance of our SingleActorInterface
, storing the pointer to the instance into a temporary variable.GetClass()
on our instance to get a reference to its associated UClass
. We need a reference to UClass,
because that object is the one which holds all of the reflection data for the object.UPROPERTY
on the object, the inheritance hierarchy for the object, and a list of all the interfaces that it implements.ImplementsInterface()
on UClass
, and it will return true
if the object implements the UInterface
in question.true
from ImplementsInterface
, we then print a message to the screen.3.145.46.18