I’m wondering how the gameobject drawer functions, exactly.
In the class it’s serialized in, its a gameobject, but somehow it serializes as a reference… is this built into the gameObject itself? Clearly a gameobject can also be serialized as a gameobject, as opposed to a reference. How does this difference happen?
It derives from UnityObject. The serializer special cases this and serializes the reference as a fileID and guid pair. You can open most unity assets that were YAML serialized into a text editor and see that, with the id references matching the ones found the referenced Asset’s meta file. Asset ids and scene object ids are handled a little differently, but still use the same format as far as the serializer is concerned.
Unity internally tracks what these ids refers to and re-links them up when it deserializes again. And its not just GameObjects, most UnityObjects support the same feature. Monobehaviors, ScriptableObjects, Textures, AudioClips… most can be used in that drawer as well.
There’s only handful of UnityObject types that can’t use that drawer. Last I checked, I remember that the “Folder” class object (which were used to represent the folders in the project panel) which isn’t supported by the drawer, but that may have changed, and there may be more.