Hi All,
I’m in the process of creating a prefab plotter editor window, after today I’ve got a good part of it working, to some degree, but I’m having the following problem.
My editor window from a combobox populates a series of buttons that represent prefabs that it finds in a directory, once I press a button it loads the prefab in using AssetDatabase.LoadAssetAtPath and then I use the editors Selection.activeObject to make this the active selection.
I set up an event that interacts with the SceneView using the SceneView.duringSceneGui event.
now once I left-click the scene view it places the gameobject at the given position. but then it automatically resets “null” the Selection.activeObject object, meaning I have to click the editor button again.
I’m using PrefabUtility.InstantiatePrefab to create the prefab, but If I use an ordinally GameObject.Instantiate it does NOT reset the Selection.activeObject, I’m I using it incorrectly or is this a bug? I’m using Editor 2021.1.5F1
if (Selection.activeObject != null)
{
//GameObject.Instantiate<UnityEngine.Object>(Selection.activeObject) as GameObject;
GameObject mObject = (GameObject)PrefabUtility.InstantiatePrefab(Selection.activeObject);
mObject.transform.position = new Vector3((float)Math.Round(mWorldPosition.x, 0), (float)Math.Round(mWorldPosition.y, 0), mWorldPosition.z);
if (mParentGameObjectCurrent != null)
mObject.transform.SetParent(((GameObject)mParentGameObjectCurrent).transform);
}
Cheers