Search Unity

Assets Folder Structure

Discussion in 'Game Design' started by IcaroDLima, May 14, 2020.

  1. IcaroDLima

    IcaroDLima

    Joined:
    Aug 6, 2019
    Posts:
    25
    Hello everyone, in this post, I would like to share with you the way that I organize my Assets folder, and that has worked very well for all my games.

    Code (Boo):
    1. .
    2. ├── YourGame
    3. │   ├── Scenes
    4. │       ├── Scene1
    5. │           ├── Fonts/
    6. │           ├── Scripts/
    7. │           ├── Textures/
    8. │           ├── Materials/
    9. │           └── ...
    10. │       ├── Scene2/
    11. │       ├── SceneN/
    12. │       ├── Shared/
    13. │       ├── Scene1.unity
    14. │       ├── Scene2.unity
    15. │       └── SceneN.unity
    16. │   └── Tools
    17. │       ├── EditorTool1
    18. │           ├── Editor/
    19. │           └── ...
    20. │       ├── EditorTool2/
    21. │       └── EditorToolN/
    22. ├── FromAssetStore1/
    23. ├── FromAssetStore2/
    24. ├── FromAssetStoreN/
    25. ├── Gizmos/
    26. ├── StreamingAssets/
    27. └── ...
    If you have any suggestions, please leave them in the comments.
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,702
    Hi,

    How do handle fonts and other assets that are shared among multiple scenes?

    Each tool has its own Editor folder. This used to be a reasonable way to organize scripts. However, if you use assembly definitions to speed up compilation and enforce modularity, you'll probably want to put all your editor scripts in one folder. Otherwise you'll end up with too many asmdefs, and it will slow down compilation.
     
  3. IcaroDLima

    IcaroDLima

    Joined:
    Aug 6, 2019
    Posts:
    25
    For this, use the following folder:
    Assets/YourGame/Scenes/Shared


    In this case, you can have a mix of the two ways, like on Unity FPSSample.

    Code (CSharp):
    1. .
    2. ├── Tools
    3.     ├── Editor          #asmdef
    4.         ├── EditorTool1/
    5.         ├── EditorTool2/
    6.         ├── EditorToolN/
    7.     ├── EditorTool1
    8.         ├── Editor/
    9.         └── ...
    10.     ├── EditorTool2/
    11.     └── EditorToolN/
    12. └── ...
     
    TonyLi likes this.
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,702
    Good job. I like how you also acknowledge that Unity has some special folder names that can't change, such as Gizmos, StreamingAssets, etc.
     
    IcaroDLima likes this.
  5. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    I usually write it like this for bigger projects:

    Code (CSharp):
    1. - 0 MyFiles // "0" so it is always the topmost folder
    2. --- 0 Core // things that are used among the whole project, like extensions, editor scripts, ...
    3. ----- Scripts
    4. --- Player
    5. ----- Scripts
    6. ----- Models
    7. ----- Textures
    8. ----- ...
    9. --- Enemy
    10. ----- Scripts
    11. ----- Models
    12. ----- Textures
    13. ----- ...
    14. - FromAssetStore1
    15. - FromAssetStore2
    16. - ...
    "Enemy" and "Player" are systems, such as "UI", "Environment", "Weapons" and so on, and everything related to it can be found in their specific folder or the folder further up, for example:
    Inside "Weapons", there are 8 different weapons, but two of them ("Pistol" and "Rifle") share the same sound file, then it can found in "Weapons/Sound" instead of "Weapons/Pistol/Sound" or "Weapons/Rifle/Sound".
    If there is no top folder, like for "Player" and "Enemey", but both use the same animations, a new folder will be created, in this case "HumanoidCharacter" - where animations are stored.

    And for smaller ones like this:

    Code (CSharp):
    1. - 0 MyFiles
    2. --- Scripts
    3. --- Models
    4. --- Textures
    5. --- ...
     
    IcaroDLima likes this.
  6. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    664
    There isn't a one fits it all folder structure in my opinion but I have a few fundamentals that I follow.
    I have projects that only have a Content folder with some assets in that and some that have 4 Levels of categorization of assets. But usually, I try to keep the folder structure as flat as possible. Once I find myself having too many objects in one folder that are not of the same purpose then I create subfolders.

    For instance, a folder of country flags is fine in one folder. But 100 UI Prefabs I would categorize in Sliders, Buttons etc.

    Also, I make use of CustomImporters sometimes, for example, to define the content of AssetBundles by location or to mark all images that are imported to a "Sprites" folder are automatically imported as Sprites.

    Code (Boo):
    1. Code
    2.     Core
    3.         Main.cs
    4.     Game
    5.     UI
    6.     Helper
    7.     Testing
    8.     IO
    9. Content
    10.     ThirdParty
    11.         AssetPackage1
    12.         AssetPackage2
    13.     Models
    14.         Buildings
    15.             BuildingA
    16.                 Materials
    17.                 Textures
    18.                 Animations
    19.                 Model1.fbx
    20.                 Model2.fbx
    21.             BuildingB
    22.         Characters
    23.     Materials
    24.     Textures
    25.     Sprites
    26.     GUI
    27.         Sprites
    28.         Animations
    29.         Prefabs
    30.         Textures
    31. Editor
    32.     Content
    33.     Code
    34.         Inspectors
    35.         EditorWindows
    36. Scenes
    37. StreamingAssets
    38. ThirdParty
    39.     SomeAPI
    40.         API.dll
    41.     FromAssetStore1
    42.     FromAssetStore2