Hello! This is just message how to use Event functions in interface and in fact is not an error at all. There is an example .H
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MyInterface.generated.h"
UENUM()
enum class EMyEnum : uint8 {
One,
Two,
Three
};
DECLARE_MULTICAST_DELEGATE_OneParam(FMyDelegate, const EMyEnum);
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UMyInterface : public UInterface {
GENERATED_BODY()
};
class MYPROJECT_API IMyInterface {
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
static FMyDelegate MyDelegate;
IMyInterface();
UFUNCTION(BlueprintNativeEvent)
void MyFunction(const EMyEnum myEnum);
virtual void MyFunctionWrapper(const EMyEnum myEnum) {
if (auto object = _getUObject()) {
if (auto actor = Cast<AActor>(object)) {
if (actor->GetWorld()) {
Execute_MyFunction(object, myEnum);
}
}
}
}
};
And .CPP
#include "MyInterface.h"
// Add default functionality here for any IMyInterface functions that are not pure virtual.
FMyDelegate IMyInterface::MyDelegate;
IMyInterface::IMyInterface() {
MyDelegate.AddRaw(this, &IMyInterface::MyFunctionWrapper);
}
PS. You see that I add check logic in function wrapper itself. So there several points that you need to solve if using this approach
- CTOR is called not only on actors in Level but also for default template objects and so on. You will need to add some code to differ the last from the others.
- As I wrote in prev comments you also need to unbind at some moment of destroying object.