Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by daivuk · Mar 31, 2012 at 09:20 PM · gameobjectsceneselect

Object picking from the scene view

Hi,

I am surprised that question haven't been asked before. Or my search skills are horrible (Probably).

I want to know if there is a shortcut or anything to pick objects from the scene view instead of having to using the "Select GameObject" dialog or to drag it from the Hierarchy.

This is really frustrating when you have a level with lot of doors and triggers.

Thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 31, 2012 at 09:38 PM 1
Share

Just to understand your question: You want to drag & drop a gameobject from the sceneview onto a script variable or something like that?

avatar image daivuk · Mar 31, 2012 at 09:40 PM 0
Share

Yes, exactly. Or when I open the "Select GameObject" dialog, just a picking in the scene view could do also.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Mar 31, 2012 at 09:57 PM

Unfortunately there's no such function, but you can work with two inspector windows if it'S really a big scene. That way you can select your object with the script so you see the variable in the inspector and then lock one inspector so it stil shows the script even when you select another object.

Now you can simply click on another object in the scene view so it get highlighted in the projectview and you can drag it from the project view to the variable (which is still visible in the locked inspector window)

To lock an inspector window you just have to click the little pad-lock-icon at the top of the window.

This is also the only way to assign a specific component to another object when there are more than one of these components on this object.

edit

I've just created an EditorWindow which allows you to pick the object under the cursor in the scene view. The picked object is shown in the custom window and you can start any kind of a drag & drop operation from there. It supports a "history stack" of the last picked objects if you want ;)

This script has to be named "SceneViewObjectWindow.cs" and should be placed in "Assets/editor/".

Just open the window via the Tools menu and dock it near the inspector window. To pick an object i've assigned the hotkey "ALT + S" (%s). You can modify it if you want a different hotkey (See MenuItem for more information).

 //SceneViewObjectWindow.cs
 using UnityEngine;
 using UnityEditor;
 using System.Collections.Generic;
 
 public class SceneViewObjectWindow : EditorWindow
 {
     static GameObject m_LastObject;    
     static List<GameObject> m_Stack = new List<GameObject>();
     
     static bool m_UseStack = false;
     static float m_MaxStackSize = 5;
     
     [MenuItem("Tools/Open SceneView Object Selector")]
     public static void OpenWindow()
     {
         EditorWindow.GetWindow<SceneViewObjectWindow>();
     }
     
     [MenuItem("Tools/Select Scene Object &s")]
     public static void SelectObject()
     {
         if (m_LastObject != null)
         {
             if (!m_UseStack)
                 m_Stack.Clear();
             m_Stack.Add(m_LastObject);
         }
         EditorWindow.GetWindow<SceneViewObjectWindow>().Repaint();
     }
     
     void OnGUI()
     {
         Event e = Event.current;
         m_UseStack = GUILayout.Toggle(m_UseStack,"Use Stack");
         if (m_UseStack)
             m_MaxStackSize = GUILayout.HorizontalSlider(m_MaxStackSize,1,20);
         
         for(int i = m_Stack.Count-1;i>=0;i--)
         {
             GUILayout.BeginHorizontal();
             EditorGUILayout.ObjectField(m_Stack[i],typeof(GameObject));
             if (GUILayoutUtility.GetLastRect().Contains(e.mousePosition) && e.type == EventType.MouseDrag)
             {
                 DragAndDrop.PrepareStartDrag ();
                 DragAndDrop.objectReferences = new UnityEngine.Object[] {m_Stack[i]};
                 DragAndDrop.StartDrag ("drag");
                 Event.current.Use();
             }
             if(GUILayout.Button("X",GUILayout.Width(20)))
             {
                 m_Stack.RemoveAt(i);
                 Repaint();
             }
             GUILayout.EndHorizontal();
             if (e.type == EventType.Repaint && m_Stack[i] == null)
             {
                 m_Stack.RemoveAt(i);
                 Repaint();
             }
         }
         if (m_UseStack && e.type == EventType.Repaint)
         {
             while(m_Stack.Count > m_MaxStackSize)
                 m_Stack.RemoveAt(0);
         }
     }
     
     [DrawGizmo(GizmoType.NotSelected)]
     static void RenderCustomGizmo(Transform objectTransform, GizmoType gizmoType)
     {
         if (Event.current == null)
             return;
         Ray ray = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast (ray, out hit))
         {
             m_LastObject = hit.transform.gameObject;
         }
     }
 }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image daivuk · Mar 31, 2012 at 10:00 PM 0
Share

Ok thank you. sad..

This was part of my 2 only complaints about Unity. Other was to generate new name for objects every time you create them: Door1, Door2, Door3. That would maybe that issue easier to deal with.

avatar image Bunny83 · Apr 01, 2012 at 12:22 AM 2
Share

I've added the script to the UnifyCommunity wiki.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using empty gameobjects as "folders" in scene hierarchy panel 1 Answer

How to reset a scene from collision with a GameObject? 0 Answers

How to make different score for different character in one scene?,how to make a different score for different character in one scene game play? 2 Answers

How to hide 3D text behind other game objects. 0 Answers

Use A button to set a color using playerprefs in a different scene? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges