One side effect of UInterfaces allowing inheritance in C++ is that we can override default implementations in subclasses as well as in Blueprint. This recipe shows you how to do so.
Follow the recipe Calling native UInterface functions from C++ in which a Physics Cube is created so that you have the class ready.
Create a new Interface called
Selectable
.Define the following functions inside
ISelectable
:virtual bool IsSelectable(); virtual bool TrySelect(); virtual void Deselect();
Provide a default implementation for functions like this:
boolISelectable::IsSelectable() { GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "Selectable"); return true; } boolISelectable::TrySelect() { GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "Accepting Selection"); return true; } voidISelectable::Deselect() { unimplemented(); }
#include "Selectable.h"
inside...