Hey everyone I need some help. Here’s my setup. I have a C++ class (BaseUnit) that inherits from APawn and implements an Interface, IInteractable (Code below). Then, i have a blueprint that inherits BaseUnit, and i would like to override the Iinteractable functions and implement them in blueprint instead. How do i go about doing that? My functions are showing up as event node that i can put in the event graph, but i can’t override them.
Interactable.h
#pragma once
#include "Interactable.generated.h"
/**
*
*/
UINTERFACE(MinimalAPI)
class UInteractable : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IInteractable
{
GENERATED_IINTERFACE_BODY()
virtual void Select() = 0;
virtual void Deselect() = 0;
};
BaseUnit.h:
UCLASS()
class ARTOFWAR_API ABaseUnit : public APawn , public IInteractable
{
GENERATED_UCLASS_BODY()
//Removed stuff...
public:
UFUNCTION(BlueprintNativeEvent, Category = "Interactive")
void Select() ;
UFUNCTION(BlueprintNativeEvent, Category = "Interactive")
void Deselect() ;
};
Anyone have any idea why i don’t have the option to override the functions?
Thanks!
Edit: Okay i’m doing what was suggested below. Now however, i can’t seem to call the function! I have a node with a BaseUnit object; when i drag it, i don’t get the option to trigger the event! Also, I can’t cast objects to my IInteractive interface… Is it possible to do that in UE4?
Technically speaking when you are attaching nodes to the event in blueprint, you are creating your overridden implementation. You can think of a series of nodes attached to an event as a function body.
To call the function, you should be able to simply find it in the context menu. Might be prefixed with the term ‘Event’.
As for the latter, you don’t cast to an interface, you simply search in the context menu for the name of the function and select the one listed under ‘Interface Messages’.
Interface messages automatically handle an attempt to cast to the target class and gracefully fail if it can’t be casted.
I’m getting neither of those. And i would like to be able to cast to my interface. I think what i’m gonna do is just make it a UObject if i can. Should fix both of my problems probably.
It seems my plan has failed. I thought i could switch Interactable to a UObject and inherit it, but the compiler tells me I can only inherit from Non-Uobjects and UInterface. Is there any other way to solve my dilemma? I just want to be able to cast to the interface and call its’ functions
That warning is basically preventing you from getting the ‘diamond’ problem in inheritance, by preventing you from inheriting UObject directly and then UObject again through the UInterface.
Were you unable to find the interface message nodes?
Also take a look at [this page][2] for more information regarding the use of interfaces. The section ‘Calling interface functions on other blueprints’ is the bit you want - the conditions it lists look to be a little out of date, as I’ve not needed to implement the interface on both blueprints for this to work, but the screenshots and overall conceptual documentation there are fine.