Hello I was looking into how unreal does its function pointers and I wanted to see if it it was possible to input an interface function with its parameters into another function that handles some extra checks and such I put an example of what I mean below
void MyFunction(InterfacesFunction Func)
{
if(MyObject)
{
// Some other code happens here
if (MyObject->GetClass()->ImplementsInterface(UMyInterface::StaticClass()))
{
// This would be an Execute_ type of function
IMyInterface::Func(MyObject);
// Some other code afterwards or whatever
}
}
}
Yes, it’s possible: https://www.ue4community.wiki/Legacy/Function_Pointers
MyInterface.h
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MyInterface.generated.h"
UINTERFACE(MinimalAPI)
class UMyInterface : public UInterface
{
GENERATED_BODY()
};
class CONTENTEXAMPLESCPP_API IMyInterface
{
GENERATED_BODY()
public:
typedef void (IMyInterface::*FunctionPtrType)(void);
virtual void F();
virtual void G();
virtual void H();
};
MyInterface.cpp
#include "MyInterface.h"
void IMyInterface::F()
{
UE_LOG(LogTemp, Warning, TEXT("F"));
}
void IMyInterface::G()
{
UE_LOG(LogTemp, Warning, TEXT("G"));
}
void IMyInterface::H()
{
UE_LOG(LogTemp, Warning, TEXT("H"));
}
MyActor.h
#pragma once
#include "CoreMinimal.h"
#include "MyInterface.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class CONTENTEXAMPLESCPP_API AMyActor : public AActor, public IMyInterface
{
GENERATED_BODY()
public:
AMyActor();
protected:
virtual void BeginPlay() override;
public:
void Foo(IMyInterface::FunctionPtrType IFunc);
};
MyActor.cpp
#include "MyActor.h"
AMyActor::AMyActor()
{
}
void AMyActor::BeginPlay()
{
Super::BeginPlay();
Foo(&IMyInterface::F);
Foo(&IMyInterface::G);
Foo(&IMyInterface::H);
}
void AMyActor::Foo(IMyInterface::FunctionPtrType IFunc)
{
(this->*(IFunc))();
}
Sweet thank you soo much! That helps clear up a ton of questions I was having relating to how to go about this with interface functions