So I currently have the following interface for certain classes, which contains the following:
UINTERFACE()
class BZGAME_API UBZGame_GameObjectInterface : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IBZGame_GameObjectInterface
{
GENERATED_IINTERFACE_BODY()
public:
UFUNCTION(BlueprintNativeEvent, Category = "Game Object")
void KillObject(FDamageEvent const& DamageEvent, AController* InInstigator, AActor* DamageCauser);
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Game Object")
USkeletalMeshComponent* GetRootMesh();
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Game Object")
USkeletalMesh* GetFirstPersonMeshAsset();
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Game Object")
UAnimBlueprint* GetFirstPersonAnimationAsset();
// Accessors for common components
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Game Object")
UBZGame_GameObjectComponent* GetGameObjectComponent();
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Game Object")
UBZGame_UnitComponent* GetUnitComponent();
};
Now, NONE of those functions need to be implemented in Blueprint at any point in my game, and I don’t really want them to be. Since the interface is mostly just used as a way to access components or variables, I want to instead do this:
public:
void KillObject(FDamageEvent const& DamageEvent, AController* InInstigator, AActor* DamageCauser);
USkeletalMeshComponent* GetRootMesh() const;
USkeletalMesh* GetFirstPersonMeshAsset() const;
UAnimBlueprint* GetFirstPersonAnimationAsset() const;
UBZGame_GameObjectComponent* GetGameObjectComponent() const;
UBZGame_UnitComponent* GetUnitComponent() const;
Maybe they can’t be const, I don’t know - but in an ideal world they’d be FORCEINLINE AND Const.
I also want to be able to simply use Cast<> instead of having to do this horrible implementation that I need to do right now.
// Ensure that the owning pawn implements the GameObject Interface
ASSERTV(OwningPawn->GetClass()->ImplementsInterface(UBZGame_GameObjectInterface::StaticClass()), *FString::Printf(TEXT("Pawn %s doesn't implement the Game Object Interface!"), *GetNameSafe(GetOwner())));
IBZGame_GameObjectInterface::Execute_KillObject(GetOwner(), DamageEvent, InInstigator, DamageCauser);
So long story short, HOW can I make my interface work this way? I still want to be able to create blueprints of these classes, but only to set defaults. None of this functionality needs to be overridden in BP.