Re: [5.4] Is there any scenario where you would use inheritance with Entity Components?

I have used inheritance for a component and it was successful. I think it is best if the base class is abstract in this case so as no to make a mistake that the base is usable. The scenario i used inheritance is this : I made a player area trigger so that it could be used for capture areas, mines and other area trigger mechanics. All of the code for creating an area and checking the area for a player was in the base class where I put the code for explosions or capturing a point in the child class. Inheritance is always useful for the reason you mentioned to avoid duplicating code and I don't think they are trying to get you to avoid it.

@mkn did he say anything about multiple inheritance? just a bit confused with the jump here.


There's already examples in the codebase where inheritance is used. The geometry components provided in the the default plugin is used in an inheritance tree.

Where is makes sense is if you have a base set of functionality e.g. loading a geometry primitive, and several specialised versions of code that make use of that functionality. It's ok for the base class to also be able to be used as a component on it's own, if that makes sense.

Favour composition, but don't throw inheritance out entirely - just use it when it's the right solution.

Re: [5.4] Is there any scenario where you would use inheritance with Entity Components?

Exactly like said previously. I use inheritance for a lot of components. I will give you simple example.

Item system for your game. Let's say you have three types of items. Weapons, armor and food.
Now, all of them will have pick up, drop methods, all of them are gonna have owner property, all of them will have models, materials etc. Why would you want to create pickup, drop etc methods and rewrite them for each type of item ? It's as stupid as it sounds. Here is where inheritance kicks in. You create item component that gathers all the functionality that they share. And then weapon component, armor component and food component will derive from item component and add it's functionality. Multiple inheritance is also welcome as long as it makes sense.
Cryengine tutorial videos on my Youtube channel! Check it out !

Who is online

Users browsing this forum: No registered users and 4 guests