Search Unity

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

Discussion in 'Data Oriented Technology Stack' started by mnarimani, Aug 15, 2019.

  1. mnarimani

    mnarimani

    Joined:
    Mar 27, 2017
    Posts:
    184
    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.
     
    mnarimani likes this.
  3. mnarimani

    mnarimani

    Joined:
    Mar 27, 2017
    Posts:
    184
    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:
    1,559
    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
    mnarimani likes this.
  5. DreamingImLatios

    DreamingImLatios

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