3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unityのguidのconflict時の解決のされ方

Posted at

背景

Unityで作成したリソースのGUIDがぶつかるとwarningが出つつ変わるのだが、この解決方法が変わったときがあったので挙動を調べた。

実験

Unity 2018.2.16f1で実験

Script1.csとScript2.csをconflictさせてみる

検証1. Script1.cs がImport済み、 Script2.cs (guid同一)が追加されたときの挙動

この状態でUnityEditorを開く

$ tree Assets/Scripts
Assets/Scripts
├── Script1.cs
└── Script1.cs.meta

0 directories, 2 files

いったんUnityEditorを閉じて、コピー

$ cp Assets/Scripts/Script1.cs Assets/Scripts/Script2.cs
$ cp Assets/Scripts/Script1.cs.meta Assets/Scripts/Script2.cs.meta

UnityEditorを開く

image.png

warningがでて、 Script1.csScript2.cs がconflictしたことにより、 Script2.cs に新しいguidが割り振られることがわかった

$ git diff
diff --git a/Assets/Scripts/Script2.cs.meta b/Assets/Scripts/Script2.cs.meta
index b6d4548..b43c0ea 100644
--- a/Assets/Scripts/Script2.cs.meta
+++ b/Assets/Scripts/Script2.cs.meta
@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: e2d1e0565f7244fe190400e5735663c1
+guid: 14ecaa395b8084260ad61be8d595fe93
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

検証2. Script1.cs / Script2.cs が未Import時の挙動

いったん検証1の状態を戻しておく

$ git checkout .

Library以下を削除することで、未Import状態を作る

$ rm -rf Library

UnityEditorを開く

image.png

Script1.csScript2.cs の両方で新しいGUIDが割り振られた

$ git diff
diff --git a/Assets/Scripts/Script1.cs.meta b/Assets/Scripts/Script1.cs.meta
index b6d4548..b253617 100644
--- a/Assets/Scripts/Script1.cs.meta
+++ b/Assets/Scripts/Script1.cs.meta
@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: e2d1e0565f7244fe190400e5735663c1
+guid: 4863cdfedb69949af9a48b4794c98200
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2
diff --git a/Assets/Scripts/Script2.cs.meta b/Assets/Scripts/Script2.cs.meta
index b6d4548..db0fc57 100644
--- a/Assets/Scripts/Script2.cs.meta
+++ b/Assets/Scripts/Script2.cs.meta
@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: e2d1e0565f7244fe190400e5735663c1
+guid: 49b3f20779ffa4ca7bab99ee1bb22a59
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

未Import状態だと競合するassetの双方でguidが新たに割り振られることが判明した

まとめ

GUIDがconflictしたとき、状況によって2つのパターンで新しいGUIDが割り振られる

  1. 片方がImport済みなとき => 新しくImportされるassetのGUIDが変わる
  2. 両方が未Importのとき => 両方のGUIDが変わる

注: Unity2018.2.16fでの挙動なので、正確な動作は手元のversionのUnityでご確認ください

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?