- Home /
Question by
unikronsoftware · May 22, 2011 at 05:42 PM ·
prefabloadassetatpath
Unexpected behaviour with LoadAssetAtPath
I am found this slightly annoying thing with LoadAssetAtPath when I create a prefab, and then attempt to link that prefab to another. This bit of code should explain what I'm doing...
GameObject go = new GameObject();
go.AddComponent<MyGameObject>();
go.active = false;
Object p = EditorUtility.CreateEmptyPrefab(myGameObjectPrefabPath);
EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
GameObject.DestroyImmediate(go);
// Do I need this?
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
currentPrefab.linkToMyGameObject = AssetDatabase.LoadAssetAtPath(
myGameObjectPrefabPath,
typeof(MyGameObject)) as MyGameObject;
EditorUtility.SetDirty(currentPrefab);
I am generating a prefab in code, and assigning it to another prefab, to automate some tedious steps in setting things up. Everything works as intended, however, an instance of the prefab containing MyGameObject is created in the scene. Is this expected behaviour, and if so, how can I destroy the object which is created? The line which seems to create the object is LoadAssetAtPath.
Is there any way to get a pointer to this object, or stop it from creating it in the first place?
Comment