Quantcast
Channel: Questions in topic: "loadassetatpath"
Viewing all articles
Browse latest Browse all 62

Unexpected behaviour with LoadAssetAtPath

$
0
0
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(); 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?

Viewing all articles
Browse latest Browse all 62

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>