Sinister Soups Serving Musings On Game Development and Play

25May/10326

Objects, Components, and Entities, Oh My!

A new post at last, and it’s that rarest of rare beasts, a programming post!

I’ve been reading and thinking about game system architecture lately. What I mean, specifically, is how objects and actors that take part in a game are represented in code, and what the relationships (in code) between them are like.

The traditional approach follows the Object Oriented programming model of a class hierarchy, where everything is represented by an object containing both data and functions, so that an Orc has both a Size value and an EatPeasant() function bundled up inside it. Furthermore, rather than writing each object from scratch, inheritance is used so that a tree of objects emerges, where specific actors like Orcs inherit much of their data and functionality from object higher up in the tree.

For example, an Orc may inherit its Size from a Monster class, as well as Position, which Monster in turn inherits from MovableObject, which inherits it from GameObject.

This is the naïve OOP approach to managing the actors in a game, and it is almost certainly the wrong approach, at least for a game of any appreciable size or complexity. Don’t get me wrong, it’s an intuitive way to set things up, especially for programmers with experience in other fields, and it can work very well for a small game where the hierarchy can be kept under control and doesn’t grow to massive, unmanageable proportions.

But there are better ways to do things, ways that are much cleaner once you have hundreds of different types of objects in your game, ways that are ultimately just as intuitive once you get used to them.

This is what I’ve been reading about, and pondering, in recent days: component-based architectures and entity systems for representing and managing the actors in your game. While I explain the concepts involved below, if you're really interested in the subject I recommend Mick West's article on the subject, which is very well written and goes into considerable detail.

At its most basic, a component-based architecture eschews a complex object hierarchy in favor of every actor in the game being a collection of components that define what that actor is, and what that actor does. Each actor then, apart from perhaps having some extremely common data such as an identifier, holds a list of components like PhysicsComponent, InputControllable, IsMonster, or whatever else is necessary to define all the operations that the actor can undergo.

These components then hold the relevant data and functions that define the actor, while centralized game systems either iterate over the actors, or even hold their own references to the individual actors’ components, and are able to do whatever updating or rendering the component requires every frame.

The benefits to this kind of setup are many. For one thing, instead of having perhaps hundreds of separate inherited objects, each necessitating its own class with all the upkeep that this entails, actors are simply the sum of their components, and any time a new component is written by a programmer, it can not only very easily be used to create new actors, but can also be trivially added to actors that already exist, giving them new functionality.

This means that with the proper tools, designers can easily redefine behavior on any actor simply by changing what components make up that actor, or tweaking the data that component manages; the only limitation is what components are available. Writing an individual component is also simpler and easier to test than modifying a fully realized, complex, working object that is being passed around throughout the game.

As an example, our Orc from before would be defined by the components that give it a size, and that allow it to eat peasants. If we then decide that Orcs should fly, we can give it a flying component, one which we might already be using for birds, or that we can subsequently use for whatever other actors we think should fly.

It also becomes trivially easy to make other Orc-like monsters, by simply swapping out a couple of components, or simply initializing the new monsters components with different data. For instance, a Goblin monster may be functionally identical to the Orc, but its SpriteComponent loads Goblin.jpg instead of Orc.jpg.

A component system within the confines of an object-oriented language like C++ or C# is all well and good, but what I found particularly interesting while reading on this subject was a method used by Adam Martin, to do away with the pesky and ill-fitting OOP paradigm entirely while designing this sort of component-based architecture.

Essentially, Adam proposes that the actors in a game (which he call entities, a common term that I have not used up until now specifically because he calls his method an Entity System) and their components should be approached using a database model.

Instead of even having an actor class which holds a list of component objects, he advocates divorcing the data and functionality of entities entirely from the traditional OOP model. An entity then becomes nothing more than a unique identifier, a number or a string, and components become packets of data needed by that entity.

Separate systems operate on the data in a component, for instance, a PhysicsSystem might take the data in a PhysicsComponent and use it modify the data in the entity’s PositionComponent, but components themselves merely hold data, not functionality.

The cool thing about this, though it took me a while to make sense of it, is that instead of passing around complex class-based objects in your code, you can simply hold onto an ID for the entity you want, and then essentially perform database-style queries to obtain any data you currently need from the components bound to that ID.

Not only do you get all the benefits of the popular and powerful component architecture, but you also keep your data separate from functionality which comes with a number of benefits; for example, it allows you to perform parallel operations easily on different entities (which are just sets of data) without breaking anything.

I feel like my thoughts about this database-like view of a component system are not yet fully formed, but I definitely feel like there is a powerful elegance to doing things this way. I will need to let the thoughts simmer some more before I have more to say about it, I think.

I recommend checking out Adam’s series of articles on the subject, linked above. It really is quite eye-opening.

Comments (326) Trackbacks (0)
  1. Hey, maybe I am being some how off topic here, nonetheless I had been reading your site and it looks great!. provillus I’m creating a blog and attempting to make it interesting, however every single time I touch it I mess something up. Did you design and style the blogsite by yourself? Can a person with very little experience do it, as well as add frequent updates without messing it up? well, great information on here, very helpful. That’s news to me; Venapro I wasn’t aware of the many ramifications and depth to this case until I surfed here through Bing! Good job.

  2. Once I originally commented I clicked the -Notify me when new feedback are added- checkbox and now every time a comment is added I get 4 emails with the identical comment. Is there any means you may remove me from that service? Thanks!

  3. It’s arduous to seek out knowledgeable folks on this matter, however you sound like you understand what you’re speaking about! Thanks

  4. Hi, Neat post. There is a problem with your web site in internet explorer, would check this… IE still is the market leader and a good portion of people will miss your fantastic writing due to this problem.

  5. Thanks i always come back to your blog to check for new posts, keep up the great work

  6. Yesterday I was googling 1 of my web-sites and saw a backlink from feedalive or something like that..My full article with links, photos etc. was published on the site. What are your ideas on full RSS feeds being published on other web sites? Do you send your full posts or partial to RSS subscribers? Thanks

  7. This web site is really a walk-by means of for all the information you wished about this and didn’t know who to ask. Glimpse here, and also you’ll positively uncover it.

  8. Thanks for the writeup. I definitely agree with what you are saying. I have been talking about this subject a lot lately with my brother so hopefully this will get him to see my point of view. Fingers crossed!

  9. I agree with most of your points, but a few need to be discussed further, I will hold a small talk with my partners and maybe I will look for you some suggestion soon.

  10. immense daybook you’ve chalk up

  11. Many thanks for being our mentor on this niche. We enjoyed your article very much and most of all liked how you really handled the aspect I regarded as being controversial. You are always rather kind to readers really like me and aid me in my everyday living. Thank you.

  12. Thank you very much for posting this info. I just want to let you know that I just check out the entire blog and and you rock! how to make a woman squirt. I can’t wait to read lots more of your posts… Good Job. Do you people have a facebook fan page or something? I looked for one on twitter but could not discover one how to make a girl squirt, I would really like to become a fan! These are the kind of posts I usually

  13. *This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want…HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  14. Great post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!

  15. I’m in search of a way to create news articles to my blog automatically. Rss would seem to be the way to go. I need a system which delivers information based on a keyword, or key phrases. I’m completely new to the RSS feed world. Does any 1 have experience with this or a similar product, to automatically post keyword filtered articles on a weblog ??

  16. I’m having a small problem. I cannot subscribe to your rss feed for some reason. I’m using google reader by the way.

  17. There are some attention-grabbing points in time on this article however I don’t know if I see all of them center to heart. There may be some validity however I’ll take maintain opinion till I look into it further. Good article , thanks and we want extra! Added to FeedBurner as properly

  18. This page appears to get a good ammount of visitors. How do you advertise it? It offers a nice individual twist on things. I guess having something authentic or substantial to talk about is the most important thing.

  19. I differ with most folks here; since I started reading this post razor e100 electric scooter I couldn’t stop until I finished, even though it wasn’t just what I had been searching for, was a fantastic read though. I will immediately get your feed to maintain in touch of coming updates. In fact, I’m just beginning in marketing male fertility test media and working on to learn how to do it well – resources like this blog are incredibly helpful. As our Site is based in the US, is kind of new to us The reference above is something that I worry too well, how to show your own real enthusiasm and share to the community.

  20. I’m honored to get a call from a friend as he uncovered the important suggestions shared on the site. Looking at your blog write-up is a real fantastic experience. Many thanks for thinking of readers just like me, and I wish you the best of success as being a professional in this field.

  21. Thanks for making the sincere effort to explain this. I feel fairly strong about this and would like to read more how to make solar panels. If you can, as you learn more in depth knowledge, would you mind posting more articles similar to this one with more tips? Sources like the one you just mentioned here will be very useful to me! I will link to this blog on my blog best registry cleaner. Thanks for dropping that link, nevertheless, it appears to be down.

  22. *Would you be interested in exchanging links?

  23. I don’t agree with most folks here; I started reading this post proactol I couldn’t stop until I was done, although it wasn’t just what I had been searching for, was a very good read though. I will immediately grab your feed to stay in touch of coming updates. In fact, I’m just beginning in marketing vigrx plus media and working on to find out how to do it well – resources like this article are very helpful. As our company is based in the US, it’s all a bit new to us. The case above is something that I worry too well, how to show your own genuine enthusiasm and share to the fact.

  24. very nice post, i certainly love this website, keep on it

  25. Zune and iPod: Most people compare the Zune to the Touch, but after seeing how slim and surprisingly small and light it is, I consider it to be a rather unique hybrid that combines qualities of both the Touch and the Nano. It’s very colorful and lovely OLED screen is slightly smaller than the touch screen, but the player itself feels quite a bit smaller and lighter. It weighs about 2/3 as much, and is noticeably smaller in width and height, while being just a hair thicker.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.