I wasn’t very clear: when I talked about selection I only meant that the user should be able to use selection and multiselection in play mode, it was not a thing I wanted to keep when switching back to the editor
About creation and deletion, I was thinking/suggesting about a more naive approach:
Each object that gets manipulated in realtime creates a struct/class like this on the object, or on a generic list of PlayTimeInfo:
PlayTimeInfo{
GameObject manipulatedObject; //null if this object has been created during playTime, otherwise this holds the reference to the actual object which has been manipulated
Vector3 localPosition;
Quaternion/Vector3 localRotation;
Vector3 localScale;
bool pendingDelete=false; // Should we delete this object when returning to the Editor?
GameObject pendingCreationObject=null; //If null, just apply the changes. If not null, first instantiate this GameObject and then apply the above settings on that
}
supposing we are able to keep this data about every manipulated object when going back to the editor, we apply all changes to objects that have the manipulatedObject == null or the pendingCreationObject != null.
if pendingCreationObject is not null, we instantiate in editor an object with pendingCreationObject as “Prefab”
we then apply all transforms.
finally, if pendingDelete == true we delete the manipulatedObject object (or, we may be entirely skipping its creation/tweaking)
During playtime:
Deleting an object = setting an appropriate PlayTimeInfo with a reference to the object about to be deleted, and pendingDelete = true
Duplicating:
if pendingCreationObject != null, then it’s a duplicated/new object
Duplicating an existing object = setting an appropriate PlayTimeInfo with a reference to the object about to be instantiated in pendingCreationObject
Duplicating a duplicate = duplicate the PlayTimeInfo, also copying the pendingCreationObject since they’re both created with the same blueprint.
Of course the new objects are not really the same (different instanceID) when going back to the editor, but since we’re probably just decorating, it shouldn’t matter.
The only important thing is to handle creations before deletions.
This is just how I’d try to implement it, there are probably more stylish ways to do it
No need to know about any serialization technique