title: Replace object instance with another in C#
body: <p>In this question I would like to find out if and how this is possible. This technique would seem extremely bad practice but it seems that the API (UnityEditor) that I am using, is doing something like this and I am just curious.</p>
  
  <p>If there are multiple references to the same object, is it possible to instantiate a new object into the same memory slot so that all previous references point to the new object?</p>
  
  <p>I figured out that the only feasible way to do so is by using unmanaged C++. Essentially the following is happening:</p>
  
  <pre><code>// Original prefab
  GameObject prefab = x;
  prefab.tag = "Untagged";
  
  // A copy of the original prefab
  GameObject prefabCopy = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
  prefabCopy.tag = "EditorOnly";  // Change from initial value "Untagged"
  
  Debug.Log(prefab.tag);     // "Untagged"   - expected
  Debug.Log(prefabCopy.tag); // "EditorOnly" - expected
  
  // Replace contents of prefab file with `prefabCopy`
  PrefabUtility.ReplacePrefab(prefabCopy, prefab);
  
  // Destroy the copy
  DestroyImmediate(prefabCopy);
  
  Debug.Log(prefab.tag);     // "EditorOnly"   - whoa?
  </code></pre>
  
  <p>Some how <code>prefab</code> is now pointing to a different object?</p>
  
  <p><em>Note: Bear in mind that Unity is built on top of the Mono flavour of .NET</em></p>