In this matter, I would like to know whether it is possible and how it is possible. This technique would seem like very bad practice, but it seems that the API (UnityEditor) I use does something like this, and I'm just curious.
If there are several references to the same object, is it possible to create an instance of a new object in the same memory slot so that all previous links point to a new object?
I realized that the only possible way to do this is to use unmanaged C ++. Essentially the following happens:
// 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?
Some, as prefab
now points to another object?
Note. Keep in mind that Unity is built on top of Mono.NET styles.
source share