logoalt Hacker News

llmslave2last Wednesday at 8:28 AM1 replyview on HN

Entity systems still rely on inheritance as you typically have an Entity baseclass that all entities derive from. That's just a single level of inheritance. Unity does this through MonoBehavior. Unreal is more inheritance-heavy but developers typically subclass something like `Actor` to one level of additional inheritance beyond the Engine's subclasses. A lot of engines will have multiple superclasses behind a Entity class, but that's an implementation detail of the engine itself and to the game developer, it's treated as a single base class that is typically subclassed a single time for the entity itself.

Even in ECS's you will often find inheritance. Some implementations have you inherit a Component struct, others will have the systems inherit a System class.

I'm sure it's still used today in some engines and by some developers but the overwhelming opinion is that doing something like Entity -> Actor -> Monster -> Orc -> IceOrc is a bad idea. Instead it would be like

   class IceOrc : Entity { components {Health, Enemy, PlayerSeek, Position, etc} }
Where each component is like

   class Health : Component { value = 100 }
And yeah, they favour composition re. Components, it's just that the components tend to inherit from a Component class. But I would still call it composition!

Replies

flohofwoelast Wednesday at 8:58 AM

Yes there is some inheritance left in those composition-systems, but a single inheritance level is really more like implementing an interface.

show 1 reply