Instantiate vs PrefabUtility.InstantiatePrefab

Instantiate

[SerializeField] GameObject cloneObject;
var clone = Instantiate(cloneObject, transform);
clone.transform.position = Vector.zero;
clone.transform.rotation = Quaternion.identity;

PrefabUtility.InstantiatePrefab

using UnityEditor;
[SerializeField] GameObject prefabObject;Selection.activeObject = PrefabUtility.InstantiatePrefab(prefabObject, transform);
var tempPrefab = Selection.activeGameObject;
tempPrefab.transform.position = Vector3.zero;
tempPrefab.transform.rotation = Quaternion.identity;

Build Errors and Solutions

Adding Define

#if UNITY_EDITOR
[SerializeField] GameObject prefabObject;
Selection.activeObject = PrefabUtility.InstantiatePrefab(prefabObject, transform);
var tempPrefab = Selection.activeGameObject;
tempPrefab.transform.position = Vector3.zero;
tempPrefab.transform.rotation = Quaternion.identity;
#endif
#if UNITY_EDITOR
// code block here
#endif

Editor Folder

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store