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());*
* }*
}