What is EditorUtility.CopySerialized supposed to do?

If I, for example, use this function with the parameters of

  1. the default Game Object in a Unity Scene, the "Main Camera"

and

  1. an empty Game Object

then "Game Object" will be renamed "Main Camera", but lose all of its components, including its Transform.

This can't be the intended use! So what is?

You need to use it on all components as well, but in my experience this results in crashing Unity. You can use it however to clone script settings to a new object. For example the script below copies the properties from JDiceSideUp script in object dice to (existing) object newDice (if script isn't there yet it will be added).

using UnityEngine;

using UnityEditor;
using System.Collections;

public class JTestEditorClass {

    [MenuItem("Ctrl-J/Set Script Properties")]
    static void TestCopy() {
    	GameObject orig = (GameObject) GameObject.Find("dice");
    	GameObject modify = (GameObject) GameObject.Find("newdice");

    	Component fromScript = orig.GetComponent(typeof(JDiceSideUp));
    	Component toScript = orig.GetComponent(typeof(JDiceSideUp));
    	if (toScript == null) {
    			toScript = go.AddComponent(fromScript.GetType());
    	}
    	EditorUtility.CopySerialized(fromScript, toScript);
    }
}

(First off, I apologize for not putting this in the comments, but UnityAnswers provides no functionality that I can see for a lengthy response, or one that includes code.) :-P

Thanks, but there is some kind of serious problem here. Using the simpler case from above, I believe the resulting script is this:

using UnityEngine;
using UnityEditor;

public class JTestEditorClass {

[MenuItem("Ctrl-J/Set Script Properties")]
static void TestCopy()
{
    Component mainCamera = GameObject.Find("Main Camera").GetComponent( typeof(Camera) );
    EditorUtility.CopySerialized
    (
    	mainCamera, GameObject.Find("Game Object").AddComponent( mainCamera.GetType() )
    );
}

}

However, after doing that, it is impossible to remove the Camera component from the previously empty Game Object. This error also occurs:

referencedGO != this

Now what?