PrefabUtility.LoadPrefabContentsIntoPreviewScene states that it returns a GameObject, signature is void.
The api documentation states that the signature for LoadPrefabContentsIntoPreviewScene
is: public static void LoadPrefabContentsIntoPreviewScene(string prefabPath, SceneManagement.Scene scene);
and that it returns the root GameObject
of the newly loaded prefab. I don't see how to reconcile this except that one is wrong. Which is it?
Answer by vkalaikkovan · Dec 05, 2019 at 09:56 AM
Please try the below lines to open the prefab in preview scene
Type t = typeof(UnityEditor.Experimental.SceneManagement.PrefabStageUtility);
MethodInfo mi = t.GetMethods(BindingFlags.NonPublic | BindingFlags.Public |BindingFlags.Static).Single(m => m.Name == "OpenPrefab" && m.GetParameters().Length == 1
&& m.GetParameters()[0].ParameterType == typeof(string) );
mi.Invoke(null, new object[] {"Prefab File path"});
How is reflection the solution here? Apparently there is absolutely a missmatch between the method signature and the documentation and one side of it should be fixed. :|
Unfortunately, this is how Unity works for years. Their dev team doesn't care
Your answer
Follow this Question
Related Questions
PrefabUtility.RevertPrefabInstance() not working 2 Answers
Create prefab from model in AssetPostprocessor without losing mesh connections? 3 Answers
can't save data in prefab and getting an error while press "Apply" in prefab! 0 Answers
can't save data in prefab and getting an error while press "Apply" in prefab! 0 Answers
PrefabUtility.CreatePrefab() results in "not a valid asset file name" error? 2 Answers