Skip to content

Commit 650d720

Browse files
authored
Merge pull request #502 from Unity-Technologies/ut-3308-dont-dirty-linked-prefab-transforms
UT-3308 Don't copy transform components into linked prefab
2 parents 49f95dc + 3f7a3c8 commit 650d720

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changes in Fbx Exporter
22

3+
## [3.0.2-preview.1] - 2020-03-19
4+
### Fixed
5+
- Blendshapes naming in FBX so that multiple blendshapes all import correctly in Maya.
6+
- Don't override transforms when creating FBX Linked Prefab, so that the prefab updates properly when the FBX transforms are modified.
7+
38
## [3.0.1-preview.2] - 2020-01-22
49
### Added
510
- Added option to export geometry when recording with the FBX recorder (in previous version geometry was always exported).

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ public static GameObject Convert(
412412
// replace hierarchy in the scene
413413
if (!isPrefabAsset && toConvert != null)
414414
{
415-
fbxInstance.transform.parent = toConvert.transform.parent;
415+
// don't worry about keeping the world position in the prefab, as we will fix the transform on the instance root
416+
fbxInstance.transform.SetParent(toConvert.transform.parent, worldPositionStays: false);
416417
fbxInstance.transform.SetSiblingIndex(toConvert.transform.GetSiblingIndex());
417418
}
418419

@@ -863,10 +864,13 @@ internal static void CopyComponents(GameObject to, GameObject from, GameObject r
863864
continue;
864865
}
865866

866-
// ignore MeshFilter, but still ensure scene references are maintained
867-
if (fromComponent is MeshFilter)
867+
// ignore MeshFilter and Transform, but still ensure scene references are maintained.
868+
// Don't need to copy regular transform (except for the root object) as the values should already be correct in the FBX.
869+
// Furthermore, copying transform values may result in overrides in the prefab, which is undesired as if
870+
// the transform is updated in the FBX, it won't be in the prefab.
871+
if (fromComponent is MeshFilter || (fromComponent is Transform && from != root))
868872
{
869-
FixSceneReferences(fromComponent, to.GetComponent<MeshFilter>(), root);
873+
FixSceneReferences(fromComponent, to.GetComponent(fromComponent.GetType()), root);
870874
continue;
871875
}
872876

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

com.unity.formats.fbx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.unity.formats.fbx",
33
"displayName": "FBX Exporter",
4-
"version": "3.0.1-preview.2",
4+
"version": "3.0.2-preview.1",
55
"dependencies": {
66
"com.unity.recorder": "2.1.0-preview.1",
77
"com.unity.timeline": "1.0.0",

0 commit comments

Comments
 (0)