Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Folder structuring

Discussion in 'General Discussion' started by Dorscherl, Nov 5, 2020.

  1. Dorscherl

    Dorscherl

    Joined:
    May 29, 2017
    Posts:
    26
    Just curious on how everybody structures their projects. I generally feel conflicted between how I organize my scripts especially

    My structure is
    • Assets
      • Project
        • Scripts
          • Mess of folders
        • Models
        • Prefabs
        • Textures
        • Materials
        • Scenes
      • Plugins
      • Resources
      • Gizmos
      • (Asset Store 1)
      • (Asset Store 2)
      • (Asset Store etc)
     
    spryx likes this.
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    For me:
    • Assets
      • App
        • Animations
        • Audio
          • Music
          • SFX
        • Graphics
          • Images
            • Sprites
            • Textures
            • UI
          • Materials
          • Shaders
        • Prefabs
        • Scenes
        • Scripts
          • Editor
          • Runtime
      • (Any folders/files that are either third-party or not directly related to the app)
    My scripts are typically organized by their namespaces.
    I.E: A script inside the "
    Stuff.Thing.Whatever
    " namespace will be located in the
    "Scripts/(Editor or Runtime)/Stuff/Thing/Whatever" directory.
     
    Last edited: Nov 6, 2020
    Dorscherl, Mauri and Amon like this.
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    I organise stuff by purpose rather than by type.

    Or, rather, I start with stuff organised by type because it's easy and requires no thought and in the super early stages assets tend to be re-used a lot for different random things. But then eventually a project grows to the point where that hurts more than it helps, so I do some spring cleaning and re-organise stuff to be stored by purpose as I go.

    When your project(s) get large enough, some of the benefits of organising by purpose rather than type are:
    • When I'm working on a thing, I want to minimise time navigating between different assets related to that thing. Having them all together helps. It also saves so much scrolling.
    • When I want to do something like "change the import resolution of all character textures" it's far easier if I can just look through the character specific part of the project folder structure.
    • It helps avoid having "dangling" assets in the project. Eg: if I replace one texture with another, it's really easy to know where the original was and remove it so it's no longer cluttering up my project and/or taking up space. (If I need it back for some reason there's always my version control history.) I can also be more confident that other stuff wasn't using the texture for other purposes, unless it's in a "Common" or "Shared" folder in which case I know I have to check. (Tools such as FindReferences2 on the Asset Store are handy when you have to do that.)
    • It's nice for doing things like exporting just relevant parts of a game. It's easier to find the relevant bits because they're already together (the dependency finder when exporting is rather overzealous, and thus not particularly useful), and they're already in a folder structure that makes sense for that thing, so when they're imported at the other end it's not adding a bunch of folders at random locations based on some other project's structure - it just ads one self-contained, locally-consistent folder somewhere.

    One thing to note is that 3rd party stuff, such as from the Asset Store, throws a spanner in the works. Not by any fault of the vendors. The model my team has moved to is having one folder for all of our own stuff for a project, and letting Asset Store stuff add its own folders which we leave alone.

    So we end up with something like:
    Code (csharp):
    1. - Assets
    2.     - OurProject
    3.         - Characters
    4.             - Joe
    5.             - Amy
    6.             - MysteriousGuy
    7.         - Worlds
    8.             - Park
    9.             - Office
    10.             - Whatever
    11.         - Vehicles
    12.         - Items
    13.         - Localisation
    14.         - Music
    15.         - Shared
    16.             - ThingThatIsDeliberatelyUsedAcrossDifferentThings
    17.         - AndSoOn
    18.     - AssetStoreThingA
    19.     - 3rdPartyToolB
    20.     - InHouseReusedToolC
    Edit: I completely overlooked scripts. :) We organise those pretty much exactly as @Vryken described. It's pretty standard and we see no reason to change it. It does mean that scripts don't end up stored with the assets they are commonly used with, but we design our scripts to be modular and reusable so that's only semi-relevant anyway.
     
    Last edited: Nov 6, 2020
    JoNax97, neginfinity, TonyLi and 4 others like this.
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    That actually sounds like a neat way to organize things. I may have to try that.
     
    Dorscherl, Amon and angrypenguin like this.
  5. Dorscherl

    Dorscherl

    Joined:
    May 29, 2017
    Posts:
    26
    Definitely some good information here. I will (try anyways) to keep my project organized with these in my thoughts.
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,528
    Structuring script folders could be a huge thread unto itself.

    In large projects, compilation can take a long time. Assembly definitions can help, but you need to find a balance.
    • The overhead from too many asmdefs can be slower than no asmdefs at all.
    • Asmdefs compile all files in a folder structure except subfolders that have their own asmdef files.
    I recently worked in a big project where scripts were spread all over the place. It wasn't practical to set up individual asmdefs because there would be hundreds (making it much slower to compile than no asmedfs) and managing the dependency assignments would be a nightmare. Since the project was far along already, they were understandably reluctant to restructure folders.

    I've been leaning more toward separate Unity projects for code, with the ability to compile DLLs into my main game project (using the excellent RockTomate asset). This absolutely enforces separation of modules. Working in each code project is snappy and responsive. And each code project can have its own test assets and test code that don't gum up the main project.
     
    Kiwasi, Ryiah and Antypodish like this.
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    I remember in past, I spent day or two converting project, to be convenient with asmdefs.
    Only to find out, startup become more sluggish than it was. We had big thread on that subject.
    After that, I wasn't focusing on them too much, as cons were stronger than potential benefits.

    For now, I keep scripts organised in one folder tree, other relevant assets in other folders / trees.
    But I am considering reorganize it at some point, as @angrypenguin pointed out.
     
  8. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,917
    I group things by scene, or scene-like, plus an overall area for general-purpose. So the folder for the WWII-computers scene hold the main script, one for the special effects, all the materials, the map and all textures, the new models... . And also things from the main area: the quiz-giver, the generic explosion textures... .

    For a camera, I might grab one from the main area, otherwise the new camera script goes into folder "WWIIcomputers" I've found with a Camera folder, it's a pain to remember what script does what, most are used only 1 time, but it's never safe to tweak them since you this might be the 1 shared camera script.

    If I want to grab an asset I know I have, I rarely have trouble remembering it's in the Factory scene, or the Telegraph area, or wherever. But I've learned to never, ever cross-link to an asset in another area. Copy it into yours, even if you aren't changing it now.

    I've never thought about this, but I wonder if Unity should add shortcuts? I could have a Camera folder with shortcuts to all of the real scripts, in one easy-to-find place.
     
  9. fyttyn

    fyttyn

    Joined:
    Nov 8, 2017
    Posts:
    2
    i'd like it if each asset store download was forced to have its own folder. Preferably using the creator's username. Then there wouldn't be packages that throw their stuff around. Really don't like asset store stuff that places loose files right into the assets folder with arbitrary names
     
  10. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    Unorganised asset means typically bad and low effort asset.
    You would be better refund straight away, if purchased.
    Unless there is really something that you after. I.e getting a texture, or mesh.
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,528
    The Asset Store curators generally don't allow new assets to put their files just anywhere any more.

    However, Unity itself does have some special folders, and certain files are required to be in there. So a properly-organized asset may have files in Assets/Editor Default Resources, Assets/Gizmos, Assets/Plugins, and other special folders like that.
     
    angrypenguin and JoNax97 like this.
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I feel like the examples are missing all the stuff that doesn't go in the assets folder. Creating a folder structure for stuff outside of the assets folder is important. (Especially for artists, who tend to spew files everywhere. Giving them a nice sandbox where they can be 'creative' away from anything project or git related is important).
    • Assets
    • Builds
      • Test build
      • Release version 1.1
        • PC
        • Mac
      • ...
    • Art
      • Concept
      • In Progress
      • Final
    • Promotional material
      • Screenshots
      • Steam storefront
      • Videos
    • Project logs (for paid projects)
    This is something I need to try. I've been slowly moving towards this kind of separation with various scene loading schemes, but a completely separate project sounds even better.
     
    vpepi, Ryiah and TonyLi like this.
  13. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Something like this. The folder names are generally less verbose though. ;)
    • Assets
      • ProjectSpecificAssets
        • Major Prefab Category
          • Prefab subcategory
          • Another prefab subcategory
        • Another Major Prefab Category
          • Prefab subcategory
        • UI stuff
        • Textures & Materials
      • Scripts
        • UI
        • Some Major System
        • Another Major System
        • Server Networking Related
        • Client Networking Related
        • Various Misc C# Classes
      • Scenes
      • My Own Cross Project Package
      • Another of My Own Cross Project Package
      • Minor Models
      • Music
      • Sound Effects
      • Major Asset Store Asset
      • Another Major Asset Store Asset