Search code examples
c#unity-game-engineunity-components

Visual component, get fed information or gather information?


I have two components, the core component and the visual component. The core component does all the game logic and does all the client/server computing. This component is always on the object, both client and server side.

Then I have the visual component, which is client side only.

My question is, should the core component tell the visual component the information it needs and the visual component completely unaware that the core component exists, or should the visual component always update and fetch information from the core component and have the core component completely unaware of the visual component existing?


Solution

  • The most straight forward approach in my opinion is that the core component should not know about the visual component. The visual component should know about the core component in order to query it, listen to events, update it, etc. This way the visual component can be replaced without affecting the core component, and also the system can support many different visual components if you go for a multiplatform game, as long as the core component(s) are also multiplatformy. Also, it is important too keep components loosely coupled. In order to easily replace components, design the system from start in a loosely coupled fashion.

    For inspiration, check out these excellent reviews of some of id's open sourced games http://fabiensanglard.net/quake3/. I believe the reviews mention the architectures of each game.