- Home /
Question by
twoxsu · Feb 13, 2017 at 01:34 AM ·
editoreditor-scriptingselectionparent and childselecting objects
Cannot set Selection.activeObject (no errors, no clues)
Hello, ive got a problem. Namely, i need to drag hundreds of prefabs into the scene, have them automatically assigned to an parent of my choice, then automatically select the parent, because i need to take a look quickly. The prefabs have assigned a script;
using UnityEngine;
using System.Collections;
using UnityEditor;
[ExecuteInEditMode]
public class EditorAutoPlacement : MonoBehaviour {
public bool selectParent = false;
public string parentName;
[HideInInspector]
public bool alreadyPlaced = false;
void Awake()
{
if (Application.isEditor && !alreadyPlaced)
{
transform.parent = GameObject.Find(parentName).transform;
alreadyPlaced = true;
if(selectParent)
{
SelectParent();
}
}
}
void SelectParent(){
Selection.activeObject = gameObject.transform.parent;
}
}
The selection does not change to the prefab's parent gameObject. I also tried Selection.activeGameObject = gameObject.transform.parent.gameObject and it did not work as intended. Cheers
Comment