- Home /
Selection.activeOject remains NULL
I have a script that I run from a menuItem. After I select an asset folder in the project view, I run the script from the context menu there.
First thing I do is determine which asset I had selected using
Object selected = Selection.activeObject;
But since upgrading to 4.3 the activeObject remains NULL, and so do the other properties of the Selection object. I've had this script working from Unity 3.5 up to 4.1.
What could be the issue here? Or should I grab the selected Object in a different manner now?
Answer by MrCranky · Dec 04, 2013 at 04:41 PM
Using 4.3.0f4, on Mac OS X, I'm seeing Selection.activeObject definitely returning non-NULL results. A simple Editor window with a label showing me the ToString() value of the Selection.activeObject shows it changing as I select things. But...
I think it depends on what you're selecting. If you're selecting something in the left-hand pane of the Project view (i.e. the folder tree), the Selection.activeObject does not change at all. Only the right-hand pane contents change. However if you select a folder in the right hand view (e.g. click on Assets in the left pane, then a sub-folder of Assets in the right-hand pane, then you should find that Selection.activeObject is an object of type UnityEnginee.DefaultAsset).
However if you then go on to select a different folder in the left hand pane, the Selection.activeObject remains the folder you originally selected in the right-hand pane. I.e. the left-hand pane is nothing to do with the Selection class. It's just a way of organising your assets. I presume that the context menu on a folder in the left-pane is the same one you'd get if you clicked in the empty space in the right-hand pane. But if you want Selection.activeObject to be the folder you're looking at in the right-hand pane, you actually have to go up one level in the tree, and select the folder from the parent listing before right clicking to get a context menu.
Thank you, this solved it for me. I guess there was a fix since the documentation never specified that the left pane would change the selection, but it did in the past.
I confess, I jumped straight from 3.6, which had no left pane at all (just a single hierarchical tree with folders and files in the same view) to 4.3, not sure about earlier versions of 4.
Answer by elijahjns · Jun 12, 2019 at 03:18 PM
I had the error if I select an object with a script before I start. Now I'm having this error if I select lights at all while the editor is running. It's goofy.
Your answer
Follow this Question
Related Questions
Cookie Header With WebPlayer Unity3d 4.3 3 Answers
Simple animation on game object doesn't play via animation.Play 1 Answer
Android Anti Aliasing broken with Unity 4.3.0 -> 4.3.2, but works on Unity 4.2. 1 Answer
Performance spikes even with almost empty scene 3 Answers
Detecting Mouse Click on 2D Sprite 4 Answers