Skip to content

Commit 03dfaa1

Browse files
committed
save original root transform to linked prefab + fix unit test
1 parent 2b623ad commit 03dfaa1

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

com.unity.formats.fbx/Editor/ConvertToNestedPrefab.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@ public static GameObject Convert(
451451
// replace hierarchy in the scene
452452
if (!isPrefabAsset && toConvert != null)
453453
{
454-
// keep the transform of the root of the prefab instance the same
455-
var jsonTransform = EditorJsonUtility.ToJson(toConvert.transform);
456-
EditorJsonUtility.FromJsonOverwrite(jsonTransform, fbxInstance.transform);
457-
458454
Undo.DestroyObjectImmediate(toConvert);
459455
Undo.RegisterCreatedObjectUndo(fbxInstance, UndoConversionCreateObject);
460456
SceneManagement.EditorSceneManager.MarkSceneDirty(fbxInstance.scene);
@@ -869,10 +865,10 @@ internal static void CopyComponents(GameObject to, GameObject from, GameObject r
869865
}
870866

871867
// ignore MeshFilter and Transform, but still ensure scene references are maintained.
872-
// Don't need to copy regular transform as the values should already be correct in the FBX.
868+
// Don't need to copy regular transform (except for the root object) as the values should already be correct in the FBX.
873869
// Furthermore, copying transform values may result in overrides in the prefab, which is undesired as if
874870
// the transform is updated in the FBX, it won't be in the prefab.
875-
if (fromComponent is MeshFilter || fromComponent is Transform)
871+
if (fromComponent is MeshFilter || (fromComponent is Transform && from != root))
876872
{
877873
FixSceneReferences(fromComponent, to.GetComponent(fromComponent.GetType()), root);
878874
continue;

com.unity.formats.fbx/Tests/FbxTests/ConvertToModelTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ public void TestStaticHelpers()
433433
b2.transform.parent = b.transform; // in alpha order
434434
a.AddComponent<BoxCollider> ();
435435
a1.transform.localPosition = new Vector3 (1, 2, 3);
436+
a.transform.localPosition = new Vector3(4, 5, 6);
436437

437438
Assert.AreNotEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
438439
Assert.IsFalse (b.GetComponent<BoxCollider> ());
@@ -441,11 +442,12 @@ public void TestStaticHelpers()
441442

442443
ConvertToNestedPrefab.UpdateFromSourceRecursive (b, a);
443444

444-
// everything except the mesh + materials should change
445+
// everything except the mesh + materials and child transforms should change
445446
Assert.AreNotEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
446447
Assert.IsTrue (b.GetComponent<BoxCollider> ());
447448
Assert.AreEqual ("BB", b.transform.GetChild (1).name);
448-
Assert.AreEqual (a1.transform.localPosition, b1.transform.localPosition);
449+
Assert.AreEqual(a.transform.localPosition, b.transform.localPosition);
450+
Assert.AreNotEqual (a1.transform.localPosition, b1.transform.localPosition);
449451
}
450452

451453
// Test GetFbxAssetOrNull

0 commit comments

Comments
 (0)