Implementing a UInterface on an object
Ensure that you've followed the previous recipe in order to have a UInterface
ready to be implemented.
How to do it...
- Create a new
Actor
class using the Unreal Wizard, calledSingleInterfaceActor
. - Add
IInterface
—in this case,IMyInterface
—to the public inheritance list for our newActor
class:class UE4COOKBOOK_API ASingleInterfaceActor : public AActor, public IMyInterface
- Add an
override
declaration to the class for theIInterface
function(s) that we wish to override:FStringGetTestName() override;
- Implement the overridden function in the implementation file by adding the following code:
FStringASingleInterfaceActor::GetTestName() { return IMyInterface::GetTestName(); }
How it works...
- C++ uses multiple inheritance ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.