Jump to content
  • Advertisement
Sign in to follow this  
jkereluk

should components access other components globally or only within the object

This topic is 3321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey all i just finished my component based system and successfuly built a console component, and a window component which both are within a system object and works quite well. i was just wondering if components should be able to talk to other components within other objects or do they just talk inside the object? currently my components can subscribe to events of other components within any object anywhere, should they only beable to subscribe to other components within there own object?

Share this post


Link to post
Share on other sites
Advertisement
There are pros and cons to each. Forcing objects to only interact with those objects that contain them or that they contain means you may be doing a fair amount of event forwarding, but also means that you'll find it easy to predict which event listeners might be affected by a given change to a component. Allowing global subscriptions means that everything can talk to everything else directly, but it'll quickly become difficult to keep track of who is and isn't talking to what.

Me, I'd probably take a hybrid approach. Allow objects to talk to each other directly, but don't provide a global object directory. So, if a component in one object wants to talk to a component in another object, it will have to ask its parent object to go get a reference to the component for it, and then it can use that reference to talk to the other component. This means that the way subscriptions get set up is easy to keep track of, but once they're set up you don't have to forward every event all over the place.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!