@@ -192,6 +192,11 @@ public static GameObject Convert (
192
192
// Copy the components over to the instance of the FBX.
193
193
SetupImportedGameObject ( toConvert , unityGO ) ;
194
194
195
+ // temporary quick fix
196
+ var temp = toConvert ;
197
+ toConvert = unityGO ;
198
+ unityGO = temp ;
199
+
195
200
// Set up the FbxPrefab component so it will auto-update.
196
201
// Make sure to delete whatever FbxPrefab history we had.
197
202
var fbxPrefab = unityGO . GetComponent < FbxPrefab > ( ) ;
@@ -376,29 +381,28 @@ private static void CopyComponentsRecursive(GameObject from, GameObject to, bool
376
381
}
377
382
}
378
383
384
+
379
385
/// <summary>
380
- /// Copy components on the 'from' object which is the object in the
381
- /// scene we exported, over to the 'to' object which is the object
382
- /// in the scene that we imported from the FBX.
386
+ /// Copy components on the 'from' object which is the object
387
+ /// in the scene that we imported from the FBX,
388
+ /// over to the 'to' object which is the object in the
389
+ /// scene we exported.
383
390
///
384
- /// Exception: don't copy the references to assets in the scene that
385
- /// were also exported, in particular the meshes and materials .
391
+ /// Only copy over meshes and materials, since that is all the FBX contains
392
+ /// that is not already in the scene .
386
393
///
387
394
/// The 'from' hierarchy is not modified.
388
395
/// </summary>
389
- public static void CopyComponents ( GameObject from , GameObject to ) {
396
+ public static void CopyComponents ( GameObject to , GameObject from ) {
390
397
var originalComponents = new List < Component > ( to . GetComponents < Component > ( ) ) ;
391
- foreach ( var component in from . GetComponents < Component > ( ) ) {
392
- // UNI-24379: we don't support SkinnedMeshRenderer right
393
- // now: we just bake the mesh into its current pose. So
394
- // don't copy the SMR over. There will already be a
395
- // MeshFilter and MeshRenderer due to the static mesh.
396
- // Remove this code when we support skinning.
397
- if ( component is SkinnedMeshRenderer ) {
398
- continue ;
399
- }
398
+ // copy over meshes, materials, and nothing else
399
+ foreach ( var component in from . GetComponents < Component > ( ) ) {
400
400
401
401
var json = EditorJsonUtility . ToJson ( component ) ;
402
+ if ( string . IsNullOrEmpty ( json ) ) {
403
+ // this happens for missing scripts
404
+ continue ;
405
+ }
402
406
403
407
System . Type expectedType = component . GetType ( ) ;
404
408
Component toComponent = null ;
@@ -415,38 +419,20 @@ public static void CopyComponents(GameObject from, GameObject to){
415
419
}
416
420
417
421
if ( ! toComponent ) {
418
- // It doesn't exist => create and copy.
419
- toComponent = to . AddComponent ( component . GetType ( ) ) ;
420
- EditorJsonUtility . FromJsonOverwrite ( json , toComponent ) ;
421
- } else {
422
- // It exists => copy.
423
- // But we want to override that behaviour in a few
424
- // cases, to avoid clobbering references to the new FBX
425
- // TODO: interpret the object or the json more directly
426
- // TODO: be more generic
427
- // TODO: handle references to other objects in the same hierarchy
428
-
429
- if ( toComponent is MeshFilter ) {
430
- // Don't copy the mesh. But there's nothing else to
431
- // copy, so just don't copy anything.
432
- } else if ( toComponent is SkinnedMeshRenderer ) {
433
- // Don't want to clobber materials or the mesh.
434
- var skinnedMesh = toComponent as SkinnedMeshRenderer ;
435
- var sharedMesh = skinnedMesh . sharedMesh ;
436
- var sharedMats = skinnedMesh . sharedMaterials ;
437
- EditorJsonUtility . FromJsonOverwrite ( json , toComponent ) ;
438
- skinnedMesh . sharedMesh = sharedMesh ;
439
- skinnedMesh . sharedMaterials = sharedMats ;
440
- } else if ( toComponent is Renderer ) {
441
- // Don't want to clobber materials.
442
- var renderer = toComponent as Renderer ;
443
- var sharedMats = renderer . sharedMaterials ;
444
- EditorJsonUtility . FromJsonOverwrite ( json , toComponent ) ;
445
- renderer . sharedMaterials = sharedMats ;
446
- } else {
447
- // Normal case: copy everything.
448
- EditorJsonUtility . FromJsonOverwrite ( json , toComponent ) ;
449
- }
422
+ continue ;
423
+ }
424
+
425
+ if ( toComponent is SkinnedMeshRenderer ) {
426
+ var skinnedMesh = toComponent as SkinnedMeshRenderer ;
427
+ var fromSkinnedMesh = component as SkinnedMeshRenderer ;
428
+ skinnedMesh . sharedMesh = fromSkinnedMesh . sharedMesh ;
429
+ skinnedMesh . sharedMaterials = fromSkinnedMesh . sharedMaterials ;
430
+ } else if ( toComponent is MeshFilter ) {
431
+ EditorJsonUtility . FromJsonOverwrite ( json , toComponent ) ;
432
+ } else if ( toComponent is Renderer ) {
433
+ var toRen = toComponent as Renderer ;
434
+ var fromRen = component as Renderer ;
435
+ toRen . sharedMaterials = fromRen . sharedMaterials ;
450
436
}
451
437
}
452
438
}
0 commit comments