Search Unity

Is this a good practice to put multiple components in one file?

Discussion in 'Entity Component System' started by Deleted User, Aug 15, 2019.

  1. Deleted User

    Deleted User

    Guest

    I find that a lot of people put related components in one file. (For example all the components related to shooting are inside ShootingComponents.cs).
    Is this a good practice?
     
  2. SeriousHatArthur

    SeriousHatArthur

    Joined:
    Aug 15, 2019
    Posts:
    19
    I think it is a matter of personal opinion/what better works for you. I doubt that DOT has some strict rules about that but I may be mistaken. I met people that were creating struct/class per file and people that had files with many struct/classes. For me: If I prototype something I mostly create everything related in one file because it is easier to work with(looking at a larger piece of code without switching files). After implementing everything, I will move it to separate files because later when project get bigger it is somehow easier for me to find my self in files if they are named like the class/struct they hold.
     
    Deleted User likes this.
  3. Deleted User

    Deleted User

    Guest

    I agree that this is personal opinion but I'm worrying about restrictions that may come in future. At some point ECS will have editor just like MonoBehaviours (and Project Tiny). How Unity is going to handle attaching components?
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Personally I usually separate them, however if I have an internal state component (for example tracking changes in another component) I may group it.

    Unity groups a bunch of their components together so there is certainly nothing wrong from it from their perspective.

    I doubt we'll have the same file name monobehaviour restrictions in the future, but on the rare chance it happens it's not like it's hard to separate them out in the future. It's 1 click to move a class/struct to it's own file in most IDEs.
     
    Last edited: Aug 15, 2019
    Deleted User likes this.
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,255
    I keep them together to keep the tab count down in my IDE. I wish I could do the same for authoring components.