Coding Memo

Unity .gitignore 관련 본문

Unity

Unity .gitignore 관련

minttea25 2022. 8. 2. 14:39

Unity 프로젝트를 노트북에서 잠깐 볼 일이 생겨 gitjub를 통해 repository를 clone 하여 프로젝트를 불러왔다. 겉보기에는 기존 프로젝트와 동일하게 보였다. 그러나 실행 시키니까 에러가 무수히 많이 뜨는 것을 보았다. 

 

이유는 scriptable object에 대한 베이스 script들이 missing 상태였고, 프리팹 내에 있는 스크립트들또한 마찬가지이며, serializefield도 일부 missing object 상태였다.

 

meta 데이터를 생성하고 컴파일 하는 중에 오류가 있었나? 하고 혹시 몰라서 zip으로 다운받아서 프로젝트를 다시 open해 보아도 똑같았다.

 


 

무엇이 문제였을까?

 

문제는 바로 .meta 파일 이었다. 어느 순간인지는 모르겠으나(...) .gitignore에 *.meta 가 포함되어 있었다.

모든 meta 파일들이 commit에서 제외된 것이었다.

처음에는 단순히 기존 스크립트나 프리팹, 씬 등의 파일에 대한 메타파일로 프로젝트 실행시에 자동으로 생성되고 캐싱되는 파일이라고만 생각했었기에 당연히 meta 파일들은 업로드 되면 안된다는 잘못된 생각을 하고 있었다.

그렇지만 전혀 아니었다.

 

구글링을 통해 아래 글을 확인한 후에 해결했다.

 

https://forum.unity.com/threads/git-results-in-missing-scripts.520603/

 

Git results in missing scripts

I followed these instructions to make a Github repository for my Unity project. However, after pushing and cloning it somewhere else, in a script which...

forum.unity.com


 

meta 파일에는 원본 파일에 대한 지침서와 같은 역할을 한다는 것을 알게되었다.

 

이후 gitignore를 다음과 같이 수정했고,

더보기
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Recordings can get excessive in size
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

/[Aa]ssets/Photon/PhotonUnityNetworking/Resources/PhotonServerSettings.asset
/ProjectSettings/EditorBuildSettings.asset
/UserSettings/EditorUserSettings.asset
/ProjectSettings/EditorBuildSettings.asset

(* Photon 관련 ignore가 다소 포함되어 있다.)

 

이 전에 gitignore에 추가를 해도 먹통인 파일이 몇개 있었기 때문에

git rm -r --cached .

명령어를 통해 캐쉬까지 삭제하고 다시 commit를 하고 문제를 해결했다.

(그동안 올라가지 않았던 meta 데이터 파일들이 많이 올라갔고 gitignore에 포함된 파일들이 updated 항목에서 제외된 것을 확인했다.)

'Unity' 카테고리의 다른 글

Unity에서 UnityWebRequest 사용 시, 에러 (Curl error60) (localhost, loopback)  (2) 2024.07.16
Coroutine 실행 에러  (0) 2023.12.22
[AddressableAssets] SBP ErrorError  (0) 2023.09.06
SerializedObject  (1) 2023.05.12
Unity Tip - UI 최적화 1  (0) 2023.05.08