Before starting always make Backups - you never know!
Cleaning Up
In general you will always need the Assets
, ProjectSettings
and the Packages
folders.
All the rest you can delete and Unity will recreate/recompile them when you open the project again.
Also see Behind the Scenes (for newer Unity versions refer to Using external Version Control instead)
When backing up a project, or adding a project to a Version Control Repository, you should include the main Unity project folder, containing both the Assets
and ProjectSettings and Packages folders. All the information in these folders is crucial to the way Unity works.
As the names say
Assets
are all your assets like scripts, images, prefabs etc. including alse the scenes.
ProjectSettings
are all general settings for your project regarding things like quality, physics, player strings etc
Packages/manifest.json
defines which packages shall be automatically imported by the PackageManager
For me also some of the Library/*.asset
files make sense to keep .. they store e.g. the build settings, target platform etc. so I don't have to configure them / switch platform from scratch every time I "reset". It's up to you of course if you want to do this as well.
You can also use any other version control system ... or of course also remove according folders and files manually but I always use GIT
for my projects.
Also refer to Using external version control systems with Unity for some general information about the setup for version controlling your project(s).
So when I want to clean up a repository before coping it I usually use the following as *.gitignore
(it is very basic - for a more complete and constantly updated version see the one on Github !).
Everything listed here can basically be deleted and will be re-compiled the next time you open the project in Unity. (Lines starting with !
are exceptions I added because as said for me it made sense to keep those as well.)
/.out/
/[Ll]ibrary/*
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*
/UWP/
# Visual Studio cache directory
/.vs/
# Autogenerated VS solution and project files
/ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
# Unity3D Generated File On Crash Reports
**/sysinfo.txt
# keep the *.asset files from Library
!/[Ll]ibrary/*.asset
If not done yet first initialize the repository running
cd your/project/root/path
git init
git add *
this will show some warnings for every file that is listed in the .gitignore
but you can ignore those warnings. It only says something similar like
You are trying to add an ignored file to the commit and it will be skipped
than run
git commit -m "Initial commit"
to make your first commit.
Now finally you can run
git clean -xfd
which removes every file that is not tracked (so be sure to have always all files you want to keep at least staged (git add
) or better commited first) or would be ignored by the *.gitignore
.
-f
If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.
-d
Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.
-x
Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.
Note If you already had a .git
repository but added / edited the .gitignore
afterwards also refer to How to make Git "forget" about a file that was tracked but is now in .gitignore?
Migrating using UnityPackage
Another option for moving scenes or parts of the Assets between two different projects is using a UnityPackage
From your current project export a UnityPackage
Excerpts from the Docs:
Use Export Package to create your own Custom Package.
Open the Project you want to export Assets from.
Choose Assets → Export Package from the menu to bring up the Exporting Package dialog box. (See Exporting Package dialog box image
below.)
In the dialog box, select the Assets you want to include in the package by clicking on the boxes so they are checked.
Leave the include dependencies box checked to auto-select any Assets used by the ones you have selected.
Click on Export to bring up the file explorer, and choose where you want to store your package file.
Name and save the package anywhere you like.
HINT: When exporting a package Unity can export all dependencies as
well. So, for example, if you select a Scene and export a package with
all dependencies, then Unity exports all Models, Textures and other
Assets that appear in the Scene as well. This can be a quick way of
exporting several Assets without manually locating them all.
alternatviely to step 2
you can also Right-Click on the Assets
folder in the Project View
and find the Export Package option in the context menu.
and then in the new project Import the UnityPackage
To import an Asset package:
- Open the Project you want to import Assets into.
- Choose Assets → Import Package → Custom Package.
- In the file explorer, select the package you want and the Import Unity Package dialog box appears, with all the items in the package pre-checked, ready to install. (See Import Unity Package dialog box image below.)
- Select Import and Unity puts the contents of the package into the
Assets
folder, which you can access from your Project view
.
Alternatively to step 2
and 4
you can even simply drag and drop the unitypackage
file into the Assets
folder via the Unity Editor.