Download

Creating an abstract class(interface)

Hi!
I’m trying to wrap my head around UE4 and it’s strange syntax. I wanted to create a class interface, called Collectable, and another called Collector and use the as mixins. Turns out checking for collision without having a base class of AActor is not possible in UE4, without creating such functionality myself.
So I’ve done some research and I came across the way UE4 handles interfaces, through the UINTERFACE() macro and it’s associated mechanisms. This seems such a cumbersome way of enforcing semantics for the engine that it even seems unreal. So, my question to those that experienced this already: Is there any other way of creating interfaces/abstract classes to work in UE4?

Unreal does things this way because of the reflection system.

You can create a Collectible interface, filling it with a list of functions that any classes who use it must implement. All of your ‘collectible’ actors can then inherit from this interface and provide the functionality. Since most items that can be ‘collected’ are probably going to handle it near enough the same way, it might be better to just create a ‘collectible’ actor base class, and have your other actors inherit from that. Anything that needs any kind of physical presence in the world must be an actor of some description.

A collector could be anything really, you can just cast an item against the collectible interface and if it succeeds, call the interface function on it.

Thanks for your answer. Please shine some light on these questions regarding your above quote:

If I can create a ICollectible_Interface and inherit from it, AND cast to it, then how is this different from an abstract base? I mean, if I can use C++ syntax, why resort to UE4’s syntax?
Can I inherit a class from multiple Interfaces too(it wouldn’t be too useful if that wouldn’t be possible)? The documentation didn’t say too much on this, but can I also add data to an Interface?

Turns out MI is possible with Interfaces, for those wondering the same thing, as far as I know. Also, data can be added just like it’s an abstract base. There are some particularities, but the documentation on the wiki should cover them.