Keeping an object selected in the hierarchy - Help

Hi, and thanks for taking the time to read my thread.

I’m trying to keep an object selected in the hierarchy. Its an empty game object, with children that are 2d planes. Whenever I click on the scene, it selected one of the children, and loses focus of the parent object.

I’d like to keep the parent object selected in the hierarchy, no matter where I click on the scene.

http://wiki.unity3d.com/index.php/2D_Tilemap_Starter_Kit
The above example is using current.Use() to keep it selected, but I’ve emulated his method, and it isn’t working. Is there another way to keep objects selected?

Any help would be appreciated, thanks for your time.

I don’t know if it’s what you want, but if you click the little padlock in the top right corner of the inspector, it keeps the selected object’s properties visible, even if you change the actual selection.

2 Likes

Thats a cool trick, and good to know, but my child objects are still selected when I click in scene. Thanks though.

So you actually want one object to remain the active selection? Via editor scripting?
In a previous project I’ve achieved this with
Selection.activeGameObject = someObject;
every loop of OnSceneGUI.

Then you just need some way to assign someObject, and enable/disable this functionality, I use an editor window, like this

	bool running = false, runningOld = false;
	GameObject mySelection;

	void OnSceneGUI ( SceneView sceneView ) {
		if ( running ) {
			if ( Selection.activeGameObject != mySelection ) {
				Debug.Log( "You clicked on " + Selection.activeGameObject );
				Selection.activeGameObject = mySelection;
			}
		}
	}

	void OnGUI () {
		if ( Selection.transforms.Length == 1 ) {
			running = GUI.Toggle( new Rect( 3, 3, 150, 20 ), running, "Lock " + Selection.activeGameObject.name );
			if ( runningOld != running ) {
				runningOld = running;
				mySelection = Selection.activeGameObject;
			}
		} else {
			GUI.Label( new Rect( 3, 3, 200, 20 ), "Select a single GameObject" );
		}
	}

Wow man, thank you so much. Its so simple, I don’t know how I missed this last week. Thanks so much, its working perfectly :smile: