Skip to content

Commit d97705c

Browse files
committed
copy over component values if the component already exists
Unless it's a MeshFilter, because then we'd be replacing the exported mesh with the old mesh
1 parent eb28aeb commit d97705c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,23 @@ private static void CopyComponentsRecursive(GameObject from, GameObject to){
159159
private static void CopyComponents(GameObject from, GameObject to){
160160
var components = from.GetComponents<Component> ();
161161
for(int i = 0; i < components.Length; i++){
162-
// if to already has this component, then skip it
163-
if(components[i] == null || to.GetComponent(components[i].GetType()) != null){
162+
if(components[i] == null){
164163
continue;
165164
}
165+
166166
bool success = UnityEditorInternal.ComponentUtility.CopyComponent (components[i]);
167167
if (success) {
168-
success = UnityEditorInternal.ComponentUtility.PasteComponentAsNew (to);
168+
// if to already has this component, then copy the values over
169+
var toComponent = to.GetComponent (components [i].GetType ());
170+
if (toComponent != null) {
171+
// don't want to copy MeshFilter because then we will replace the
172+
// exported mesh with the old mesh
173+
if (!toComponent.GetType ().Equals (typeof(MeshFilter))) {
174+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
175+
}
176+
} else {
177+
success = UnityEditorInternal.ComponentUtility.PasteComponentAsNew (to);
178+
}
169179
}
170180
if (!success) {
171181
Debug.LogWarning (string.Format ("Warning: Failed to copy component {0} from {1} to {2}",

0 commit comments

Comments
 (0)