1

I have been redesigning all my entities in Unity in the hopes that they will be more modulated and the components will be less dependent on each other. However, I have run into problems that I can't seem to get around.

If I have two script components on an entity, for example, PlayerInput and PlayerState. PlayerInput would take input and use it in some meaningful way, and PlayerState would manage the state of the player. PlayerState might hold some data that describes what state the player is in. The problem is if that state data is needed for dealing with input, then there's not much of an option but to create a dependency, or change the base game object class( which I can't do, and probably wouldn't be a good idea anyway. )

Of course sending messages is only useful for giving out information, and not requesting it. Should I even be trying to share data across components, or is that implying a dependency in itself? What am I doing wrong in this situation?

user3071284
  • 6,955
  • 6
  • 43
  • 57
Ben
  • 1,816
  • 1
  • 20
  • 29
  • You're missing the idea of a "controller" in your scenario. You need some object to coordinate the interaction between your various components. Otherwise, sending messages every which way will completely defeat the purpose of encapsulating behavior in separate components. – Zach Thacker Oct 01 '14 at 14:32
  • @SirBraneDamuj So you're saying some components need to have dependencies? If a component needs to be controlled, doesn't that make it somewhat dependent on it's controller? – Ben Oct 01 '14 at 14:41
  • The way i request data is i send a message to a receiver and attach a delegate that the receiver uses to respond with. – Imapler Oct 03 '14 at 12:14

0 Answers0