Applying Inheritance on UInterface

Given these class and interface defintions:

    UInterface()
    class UWeapon : public UInterface
    {
    GENERATED_UINTERFACE_BODY()
    };

    class IWeapon
    {
     GENERATED_IINTERFACE_BODY
         // some method declaration
    };

Now, suppose there is some other interface IRangedWeapon, for instance, that is supposed inherit from IWeapon.
Any of the following defintions will cause compilations errors:

UInterface()
class URangedWeapon : public UInterface, public UWeapon 

UInterface()
class URangedWeapon : public UInterface, public IWeapon

class IRangedWeapon : public IWeapon

Those were the most intuitive solutions to me. Seeing there is no documentation concerning this, I resolved to these forums.

I don’t think UE4 interfaces support inherence, but last option without UINTERFACE should compile i think. What kind of error do you get?

Looking on what you trying to do makes me wonder why you need interface at all? Why don’t you use standard class inherence? AActor → AItem (if you have something else then weapon) → AWeapon → ARangedWeapon?

I did read somewhere once, I forgot the source (it was a while ago), that I have to inherit from the first class - the one starting with the ‘U’.

The error messages received are: “Missing ‘{’ in ‘Class’”. Double clicking the message points to the declaration of the class.

Thank you for your suggestion; that was one of my first design drafts to be honest. That design has a drawback though: When wanting to pick an item up, it should disappear in some kind of inventory, like a rucksack, bag, or whatever. Despawning the actor and remembering some item ID would be more by far cheaper memory-wise than keeping the actor instance alive. Remembering some type of item ID is what many other games, for instance minercraft, do under the hood, too.
Furthermore, weapons don’t have to be actors. As such, my conclusion is that interfaces are better to use as they by definition do not bind and implementation.

Not supporting inheritance would be a kind of bad though. Many mainstream language, such as Java, support it. Even C++ supports it indirectly with abstract classes (but sadly Unreal prohibits multiple inheritance on UCLASSes, but for different trade-offs).

Maybe replace UInterface() with UINTERFACE() as it’s case-senstive. UE4 does not prevent you to use multiple Inherence, it’s only UObjects, you can inherend from non-UObjects which even engine does that and thats how you implment interfaces to classes. C++ does not formally support interfaces, it can only emulated it thru clases and there multiple inherence and thats what UE4 does. Also importent note UE4 even thru it got some extra rules, you need to keep in mind this is reflection system rules not C++, you can use all C++ features as long as they stay away from reflection system and UHT eyes, even engine code practice that.

ID idea should work fine in UE4 (but i think using UClass* will be more comfitible to use in UE4 envraiment and you can read item data from it from defaults from CBO), but keep in mind by doing that you lose data about items and Minecraft didn’t need that data as well as your item will be just data, you wont be able to apply code to it (or else you will do some crazy stunting with object).

Actors alone don’t take much of perfomance and memory, prime diffrence between actor and object, is that it’s attached to the world instance and it can carry components and components are one that do most of the work in actor. In UT as well as most Unreal game only one class is made per item, they simply manipulate components of it, when item is picked it hides or removes mesh component and start manipulating player character.

Weapons need to be Actors i don’t know how othe way you plan to implemntemt in reality.You need to use actor if you want to create something attached to the world instance, even if it’s not physical, even engine use AGameMode and APlayerController as actor as they are part of the world, All actors are also cleaned then you switch levels or restart the game

Thank you for pointing out the interface macro; that is plainly a typo in my question. The information you provided was very detailed, if that were an answer to its own respect I would accept it.

I am rather convinced to use actors instead of interfacing everything in order to keep the design simple - though I will use the ID system.Minecraft, now that we are already talking about it, does not remember only some item ID for items in inventory but rather some object called item meta data, which stores an item’s important information, such as ID, enchantements, etc.

I do have another question as I am still to expand my knowledge on Unreal’s API: When an actor is spawned all its components are set up correctly so that for instance I might see a sword, banana, or whatever. How does Unreal retrieve what components to give the actor? I had the same idea as you suggested with just clearing the components on picking up an item. What I cannot find by researching is how to retrieve the components to be added for a certain subclass of actor.