Sign in to follow this  
Nairb

Unity Component Based Architectures

Recommended Posts

Inspirations for this post: Component Based Game Architectures - GDNet Post Outboard component-based entity system architecture - GDNet post Object Oriented Game Programming: The Behavior System 301: Introduction to Dungeon Siege Architecture Various Bilas presentations Some stuff written by Jeremy Chatalaine So, now to begin with the actual post. :-) I'm toying around with writing a purely component-based architecture, perhaps making something crazy data driven, and I was wondering what other people were doing here. I haven't read the GPGems articles on the topic, so I'm probably missing some details, but I'm grabbing everything I can find online. My knee-jerk idea was to create one master "GameObject" class which consisted of a list (or map, more technically) of components and never subclass that, simply define various schemas via XML or some other mechanism. Communication between components would either be done via a signal/slot mechanism or by providing a QueryInterface in the GameObject class such that a component could search for another component if it wanted that information. Signal/slot seems cleaner design-wise, but QueryInterface seems more compact. For instance, if something needed a Position component (hypothetical example - something so granular may not be a good candidate for its own component) to do its rendering at the right location, with the signal/slot mechanism the new position would have to be stored until needed, whereas with the QueryInterface it could just be used and discarded on demand. That was the knee-jerk reaction, of course, and it left me with all sorts of questions about how certain things would be handled. For instance, what happens when game objects need to know about each other (when pathfinding, for instance)? It seems like the common way is to have some master database and run queries on that database to find entities with the appropriate components? Further, what do I do about entities that should be added to the scene graph versus those that shouldn't? Upon creation of the entity, should the scene graph check its components and add it as necessary? I think I'm missing some key piece here. What about entity-specific behaviors? A person with a bow attacks differently than a person with a sword or gun, hence a general 'Attack' component doesn't seem practical. Is this where different kinds of Attack components (Attack_Sword, Attack_Gun) come into play, or is this where subclassing becomes the only pragmatic possibility? So it seems like having one master GameObject class is a little impractical, and that I'll be forced to throw in game-specific code, which is not necessarily a bad thing of course. I wonder about things like managing a bunch of interacting entities (for instance, parts of a window in a GUI). It seems like if I fit some scripting solution in, game-specific code would turn into scripted code, which may be ideal. So, again, I was wondering how other people were implementing their solutions. I realize right now that I'm trying to treat component-based design as a golden hammer or magic bullet, so where are you guys drawing the line? Or are you even using this at all? Cheers, --Brian

Share this post


Link to post
Share on other sites
Quote:
That was the knee-jerk reaction, of course, and it left me with all sorts of questions about how certain things would be handled. For instance, what happens when game objects need to know about each other (when pathfinding, for instance)? It seems like the common way is to have some master database and run queries on that database to find entities with the appropriate components? Further, what do I do about entities that should be added to the scene graph versus those that shouldn't? Upon creation of the entity, should the scene graph check its components and add it as necessary? I think I'm missing some key piece here.
I've laid out my thoughts on this in a couple of the threads you linked, so I'll abstain from these questions.

Quote:
What about entity-specific behaviors? A person with a bow attacks differently than a person with a sword or gun, hence a general 'Attack' component doesn't seem practical. Is this where different kinds of Attack components (Attack_Sword, Attack_Gun) come into play, or is this where subclassing becomes the only pragmatic possibility?

Compare these two situations:

class FooBase {
public:
virtual int exec() = 0;
};

class FooOne : public FooBase{
public:
virtual int exec() { return 1; }
};

class FooTwo : public FooBase{
public:
virtual int exec() { return 1; }
};



class Foo {
public:
Foo(int i) { m_i = i; }
int exec() { return m_i; }
private:
int m_i;
};


It's pretty clear which one of these approaches is clear and elegant, and which one is rigid and overly verbose. But the situation can go the other way:


class FooBase {
public:
virtual int exec(int a, int b) = 0;
};

class FooAdd : public FooBase{
public:
virtual int exec(int a, int b) { return a+b; }
};

class FooSub : public FooBase{
public:
virtual int exec(int a, int b) { return a-b; }
};



enum Operation { OPERATION_ADD, OPERATION_SUB };

class Foo {
public:
Foo(Operation o) { m_o = o; }
int exec() {
switch(m_o) {
case OPERATION_ADD: return a+b;
case OPERATION_SUB: return a-b;
default: assert(false);
}
private:
Operation m_o;
};


Here, denying the fundamental difference between the two operations leads to less readable, less trackable code. So there's no easy answers, except "try it out, and if it doesn't work out, try it the other way". As you get more accomplished, you'll learn to get it right the first time most of the time, but at least for now you'll get it right the second time.

One dimension, however, that does have a simple answer, is that this sort of subclassing should be confined as tightly as possible. See the strategy pattern for more details on this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
I've laid out my thoughts on this in a couple of the threads you linked, so I'll abstain from these questions.


Ah, so you do. Very first post in that second link, as it turns out. I think I managed to interpret a large portion of the discussion as pertaining to inter-component communication, and by the time I'd hit the end I'd forgotten all about that first bit.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628285
    • Total Posts
      2981837
  • Similar Content

    • By Simplepg
      https://play.google.com/store/apps/details?id=simple.gplay.GamesInABox
    • By Simplepg
      https://play.google.com/store/apps/details?id=simple.gplay.GamesInABox
    • By ForgedInteractive


      Who We Are
      We are Forged Interactive, a small team of like-minded game developers with the sole purpose of making games we love! We're a team of artists, animators, programmers, level designers, writers, composers, producers, and other creative minds. We want to make games that you, the modern gamer want to play! We hope to build a community that enjoys our games as much as we love creating them. With your feedback and support we will be able to achieve that.

      About the Game
      GAME NAME is a fun, action-packed army builder with unique characters, challenges and engaging levels. Set forth on an adventure to protect friends, family and countrymen from new adversaries. Once defeated your enemies turn coat and join you in your adventures. Players can enjoy a range of troops and abilities based on their gameplay style which become more important as maps introduce more challenging terrain, enemies and bosses. Strong orc knights, dangerous shamans, and even a dragon are out on the prowl. Knowing when to fight and when to run, and how to manage your army is essential. Your actions alone decide the fate of this world.

      Previous Work by Team
      Although we are working towards our first game as a team, our team members themselves have past experience in the industry.
      This includes members who have worked on titles including:
      Final Fantasy Kingsglaive, FIFA, Xcom 2 and Civilization.

      Who are we looking for? 3D Modellers Concept Artists Marketing Specialists Level Designer

      What do we expect? Reference work or portfolio. Examples what have you already done and what projects you have worked on academic or otherwise. The ability to commit to the project on a regular basis. If you are going on a two-week trip, we don't mind, but it would be good if you could commit 10+ hours to the project each week. Willingness to work with a royalty based compensation model, you will be paid when the game launches. Openness to learning new tools and techniques
      What can we offer? Continuous support and availability from our side. You have the ability to give design input, and creative say in the development of the game. Shown in credits on websites, in-game and more. Insight and contacts from within the Industry.
      Contact
      If you are interested in knowing more or joining. Please email or PM us on Skype. Myself or Colin will reply to you within 48 hours.

      E-mail: Recruitment@ForgedInteractive.com
      Skype: ForgedInteractive

      Regards,
      David and Colin

      Follow us on:

      Facebook: https://www.facebook.com/ForgedInteractive/
      Twitter: @ForgedInteract
      Youtube: https://www.youtube.com/channel/UCpK..._as=subscriber
      Reddit: https://www.reddit.com/user/Forged_Interactive/
    • By Eck
      I just saw their courses were knocked down to $10 each and figured I'd share the info here. They have stuff for Unity, Unreal, drawing, business, etc. I haven't used their stuff before, but the previews I looked at seemed pretty good and there is a user review system as well.
      https://www.udemy.com/courses/search/?q=Unity&src=ukw
      - Eck
       
    • By zizulot
      first and only logo , for now
  • Popular Now