GameObject created outside MonoBehaviour losses it's variables for all added components?

I have written a ‘dynamic prefab’ asset that can be saved during run-time.
To track all the instances of the prefabs in my scene I add a component that stores a GUID.

Then when I try to read the GUIDs they all return null (00000000-0000-0000-0000-000000000000);

The GUID is set outside MonoBehaviour, so is this a problem in the C++ layer of Unity or am I missing something?

PS: adding the GUID from within MonoBehaviour (making my ‘dynamic prefab’ class MonoBehaviour) is not a option here. This will mean I can’t use ‘new’ and create more overhead then is needed.

Code that loads the prefab to the scene and sets the GUID:

    public class SerialPrefabHandler : IXmlSerializable {

        ...

    public GameObject GetInstance(){
            		if (_isLoaded) {
            			GameObject root = new GameObject(Name + "_root");
            			for (int i = 0; i < _PreLoadedObjects.Count; i++) {
            				GameObject obj = (GameObject)GameObject.Instantiate(_PreLoadedObjects*);*

_ SerialPrefab SPF = obj.AddComponent();_
SPF.GUID = Prefabs.GUID;

* obj.transform.parent = root.transform;*
obj.transform.localPosition = Prefabs*.Position;
obj.transform.localRotation = Quaternion.Euler(_Prefabs.Rotation);
obj.transform.localScale = Vector3.one * _Prefabs.Scale;*

* }*

* return root;*
* } else {*
* Debug.LogError(“Can not Instantiate DynamicPrefab befor preloading it.” +*
* “use DynamicPrefab.Preload() befor calling DynamicPrefab.GetInstance().”);*
* }*
* return null;*
* }*
}

SerialPrefab class:

public class SerialPrefab : MonoBehaviour {
* public System.Guid GUID;*

* void Awake() {*
* Debug.Log (“Loaded SerialPrefab:” + GUID.ToString());*
* }*
}

System.Guid is a struct and Unity cannot serialize structs. So any struct set with a value before runtime will reset when you start the game. You will need to create your own serializable guid class. It could always be a wrapper around the System.Guid, so you don’t have to generate the unique id yourself.

As GameVortex pointed out to in in the comments:

Wait, I just saw your Debug.Log in SerialPrefab. Is that where you are saying the GUID values are empty? Awake happens immediately when adding a new component, so your debug is printing before you are adding the GUID value. Have you checked the values anywhere else in your code (for example in update or start)?