Search Unity

Id like to restructure my entire project, how to?

Discussion in 'Editor & General Support' started by SleepyWolfie, Feb 18, 2021.

  1. SleepyWolfie

    SleepyWolfie

    Joined:
    Jun 8, 2020
    Posts:
    36
    Basically, I want to redo my projects folder structure. I tried in the past, but it led to many terrible problems and I want to do it well.

    I am aware that I should restructure in the Unity Editor (to generate and edit the meta files). Any other tips? To avoid the project blowing up?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    First, put the project in source control before you do ANYTHING.

    Second, work iteratively and ONLY move files/folders from inside the Unity structure. After each step, exit Unity and commit all the changes to source control.

    If you follow the above to steps it's easy. I'm constantly moving crud around in my games when I find things are poorly organized. I also use source control religiously for every project I work on, tiny to large.

    Personally I use git because it is free and there are tons of tutorials out there to help you set it up.

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837
     
    SleepyWolfie likes this.
  3. SleepyWolfie

    SleepyWolfie

    Joined:
    Jun 8, 2020
    Posts:
    36
    Hi Kurt, thanks for answering so quickly!

    Firstly dont worry, I do source control on everything I do on every project I have (small or big as well). I use Git alongside Git Hub and its desktop app (Ive learned to use the CLI of Git, but Im much more comfortable with these tools).

    I was more interested on the second point and Ill do the following as you suggest:
    1 Branch to a "Folder-Restructure" branch on git.
    2 Make a restructure step
    3 See that everything works and close unity
    4 Commit.
    5 Do 2 - 4 iteratively.

    Furthermore, If you have any heads up on possible problems that may arise from restructuring the folders (as it happened to me the first time I wanted to do so, thankfully I had commited and could go back to a stable version of my project, indeed Source Control is golden!)
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    If it is just references to things dragged into prefabs, scenes and scriptable objects, those only rely on the GUID in the meta file.

    This means if you move them by the Unity file browser, all will be golden.

    If you are loading stuff with
    Resources.Load("MyPath/ToThe/Asset")
    and change the path, well, that's not gonna work.

    Unity has some sloppy file-write and file-flush errors with the
    ProjectSettings/EditorBuildSettings.asset
    list of scenes not being properly updated when you move or rename scenes. In past versions of Unity it failed 100% of the time. In current versions I've seen it fail and work, so not sure.

    If you move scenes around, I find the solution is to move the scenes, then open the Build Settings window, toggle at least one scene on / off (enabled in the list), then close Unity and the paths SHOULD be updated.
     
  5. SleepyWolfie

    SleepyWolfie

    Joined:
    Jun 8, 2020
    Posts:
    36
    Very well, thanks for the heads up! Ill update on my progress on this.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    ALSO: Remember to NEVER EVER EVER EVER rename a MonoBehavior using Visual Studio or MonoDevelop.

    First: rename the C# file in Unity (
    OldClassName.cs
    to
    NewClassName.cs
    )

    Second: use Assets -> Open C# Project to recreate the VS / Mono project and THEN rename the class

    Otherwise the meta file will be regenerated with different GUIDs and all your scripts will be Missing and you will be sad panda.
     
  7. SleepyWolfie

    SleepyWolfie

    Joined:
    Jun 8, 2020
    Posts:
    36
    Noted! I didnt know that. I tried before, and I realized that the metas didnt change, so Id create a new script with the right name and then copy paste and delete the last one, etc. Quite an annoying process.
     
    Kurt-Dekker likes this.
  8. SleepyWolfie

    SleepyWolfie

    Joined:
    Jun 8, 2020
    Posts:
    36
    Hey, Im here just to mention that I managed to restructure the entire project to a scheme that fits the project. Thanks Kurt for the advice, it really helped and I really recommend this method of doing folder restructuring and such.
     
    Kurt-Dekker likes this.