1
\$\begingroup\$

I have implemented Scene loading in my game and have three scenes: Persistent, Main Menu and Game

By default, the player is loaded into the Persistent scene, which immediately loads the Main Menu, and when the player clicks on Play, Main Menu is unloaded and Game is loaded.

Now, the two active scenes are Persistent and Game.

However, I have a script with OnDrawGizmos on a GameObject in the Game scene. It seems that by default gizmos only begin to be drawn when I click on that GameObject, sort of activating it, and everything works fine. This used to just work before because Game was my only scene and Unity automatically selected that first GameObject. Now, with multiple scenes, no GameObject is selected by default and my gizmos won't draw until I manually click on it.

How can I solve this?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ OnDrawGizmos and OnDrawGizmosSelected handle unselected/selected game objects. I'd suspect in your case it's not so much about selecting the object as selecting something in the scene. Unity might disable gizmos from scenes other than the one containing your last selection, either to reduce scene view clutter or improve performance in multi-scene editing. \$\endgroup\$
    – DMGregory
    Commented Mar 23, 2021 at 14:32

1 Answer 1

0
\$\begingroup\$

I think you're looking for this

Selection.activeGameObject = {Whatever object you want selected}

\$\endgroup\$
3
  • \$\begingroup\$ I had the same issue and this solution solved it. But with this I can't build my project. What can I do for that? I saw that changing build setting from gradle to internal could solve this but I'm using unity 2020.3 and that option is not available here. \$\endgroup\$ Commented Jul 14, 2021 at 5:12
  • \$\begingroup\$ @Kavisha presumably you considered wrapping your use of the UnityEditor namespace in an #if UNITY_EDITOR preprocessor directive, so that it's not included in standalone builds? \$\endgroup\$
    – DMGregory
    Commented Jul 14, 2021 at 10:21
  • \$\begingroup\$ @KavishaSamarasinghe Any scripts in a folder called "Editor" will not be included in the final build. Likewise, as @DMGregory says, you can wrap any code using editor extensions in a #if UNITY_EDITOR ... #endif. Any code between those directives will be cut out before building. \$\endgroup\$
    – Basic
    Commented Jul 14, 2021 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .