- Home /
Set Selection.activeGameObject C#
Hi All,
I'm attempting to set a game object to be the UnityEditor.Selection.activeGameObject
inside of the MonoBehaviour.OnDrawGizmos()
method. It works for a frame and then immediately deselects the gameObject.
I have also tried Selection.activeTransform = transform
and even copying the Selection.objects
array and adding one more Object and reassigning it, to no avail.
Any insight?
Thanks,
I know this is an old question, but did you ever find a solution? I'm having the exact same issue now :)
Could you tell us what Exactly you are trying to do with examples of code? In other words, how can we recreate this?
Answer by Fritsl · Sep 03, 2016 at 07:07 PM
Selection.activeGameObject is apparently only thought as a 'GET' from Unity Developers - There's also multiple issues with the two-rows project window when trying to use it as 'SET'.
I'm trying hard to convince them that there's a strong need to set it - so far no luck. (It CAN be used to set, but it's very buggy in actual use from EditorWindow)
$$anonymous$$y post of this issue has over 590 followers
$$anonymous$$ust be serious and hasn't got any serious Unity attention after one year?
I too have run into this loose anomaly. As in the post the VS compiles it but the Unity build fails. I have to agree with you that Unity needs to look at this. This seems to me to be a loose end or a non compliance somewhere in their system. Lets put this under NFT(Not Fully Tested) or TOTGA(The one that got away) category. It happens in large systems.
$$anonymous$$aybe after a year there is a fix...
This question here is completely unrelated to your question. You simply used it wrongly in a runtime script. The Selection class is an editor class and can only be used inside the editor. This question was about the fact that the assignment see$$anonymous$$gly had no effect when using it inside the Editor. However i can't really confirm or reproduce this issue here.
Hi @giantkilleroverunity3d I think @Bunny83 is correct about it being a different issue- although he probably could've used more tact.
I haven't had to deal with this issue in some years so I'm not even certain it exists any more.
I willfully and humbly accept the answer no matter what the tone. From my position I didn't understand how deep the question was as compared to how I inadvertently got there. Just the same, I now have a better understanding of what I actually did in lieu of what I thought I was accomplishing. I was using a previous PC game project and just trying to push it as is to the Oculus GO to test the headset with my code. I now know better. I have some more work to do. The previous project also has some FBX and $$anonymous$$ax files in it of which I will use Wings3d to redo the objs. That way I truly own my own work.
Your answer

Follow this Question
Related Questions
Level selection from main menu? 4 Answers
"add selected" editor script 1 Answer
Editor scripting, select a field 1 Answer
Selected object into next scene? 3 Answers
Selection Question 1 Answer