@@ -117,18 +117,27 @@ public static GameObject Convert (
117
117
string directoryFullPath = null ,
118
118
string fbxFullPath = null )
119
119
{
120
- if ( toConvert . transform . parent == null ) {
121
- PrefabType unityPrefabType = PrefabUtility . GetPrefabType ( toConvert ) ;
122
- if ( unityPrefabType == PrefabType . ModelPrefabInstance ) {
123
- // don't re-export fbx
124
- // create prefab out of model instance in scene, link to existing fbx
125
- var mainAsset = PrefabUtility . GetPrefabParent ( toConvert ) as GameObject ;
126
- var mainAssetRelPath = AssetDatabase . GetAssetPath ( mainAsset ) ;
127
- var mainAssetAbsPath = Directory . GetParent ( Application . dataPath ) + "/" + mainAssetRelPath ;
128
- SetupFbxPrefab ( toConvert , mainAsset , mainAssetRelPath , mainAssetAbsPath ) ;
129
-
130
- return toConvert ;
131
- }
120
+ // Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
121
+ // Children of model prefab instances will also have "model prefab instance"
122
+ // as their prefab type, so it is important that it is the root that is selected.
123
+ //
124
+ // e.g. If I have the following hierarchy:
125
+ // Cube
126
+ // -- Sphere
127
+ //
128
+ // Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
129
+ // However, when selecting the Sphere to convert, we don't want to connect it to the
130
+ // existing FBX but create a new FBX containing just the sphere.
131
+ PrefabType unityPrefabType = PrefabUtility . GetPrefabType ( toConvert ) ;
132
+ if ( unityPrefabType == PrefabType . ModelPrefabInstance && toConvert . Equals ( PrefabUtility . FindPrefabRoot ( toConvert ) ) ) {
133
+ // don't re-export fbx
134
+ // create prefab out of model instance in scene, link to existing fbx
135
+ var mainAsset = PrefabUtility . GetPrefabParent ( toConvert ) as GameObject ;
136
+ var mainAssetRelPath = AssetDatabase . GetAssetPath ( mainAsset ) ;
137
+ var mainAssetAbsPath = Directory . GetParent ( Application . dataPath ) + "/" + mainAssetRelPath ;
138
+ SetupFbxPrefab ( toConvert , mainAsset , mainAssetRelPath , mainAssetAbsPath ) ;
139
+
140
+ return toConvert ;
132
141
}
133
142
134
143
if ( string . IsNullOrEmpty ( fbxFullPath ) ) {
0 commit comments