This class could have any on this ABCustomComponent or ACCustomComponent, is there any way of make this possible? i try with TSubcalssOf but this didn’t work, any one have any advice on how to make this possible? of i will have to create a custom class for each.
If I understand the questions correctly, you are asking how to make an interface in Unreal Engine C++. This is possible, and you can find the docs on how to do it here.
The concept works the same as it does in normal C++, you just have to add some meta data to your interface class.
Benja, so try this, but i got a question, this “UInterfaceComponent” should be a child class from UActorComponent right??
like this?
class UCustomInterface: public UInterface, public UActorComponent
{
GENERATED_BODY()
};
/**
*
*/
class TESTGAME_API ICustomInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION()
virtual void A() = 0;
};
Or Like this?
class UCustomInterface: public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class TESTGAME_API ICustomInterface: public UActorComponent
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION()
virtual void A() = 0;
};
Your interface class itself doesn’t need to inherit from UActorComponent. The Interface should just have your methods that you want to implement in your child classes.
The components that you make to implement that interface should all inherit from UActorComponent and your custom interface.
Well, but the interface itself dont have a metoc called DestroyComponent() or RegisterComponent()
ICustomComponentInterface* CustomComp = nullptr;
When i try to compile this i get this error:
**********************\ICustomComponentInterface.cpp(32): error C2039: 'DestroyComponent': is not a member of 'ICustomComponentInterface'
**************/ICustomComponentInterface.h(21): note: see declaration of 'ICustomComponentInterface'
*************************\ICustomComponentInterface.cpp(37): error C2039: 'RegisterComponent': is not a member of 'ICustomComponentInterface'
*************************/ICustomComponentInterface.h(21): note: see declaration of 'ICustomComponentInterface'