Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 keganheiss · Oct 09, 2018 at 08:35 PM · editoreditor-scriptinghandlesdrawline

How to create persistent handles in Editor Scene View?

Hello!

I'm trying to draw a line between objects in the Scene View that will appear regardless of whether the object(s) are selected or not. I've figured out how to make the line appear when the object is selected. The same question was asked and answered ages ago (2011), but that solution is causing me errors.

Here's my current Code...

Saved in the Editor folder:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(LinkedObjectSet))]
 class LinkedObjectLineDrawer : Editor
 {
     void OnSceneGUI()
     {
         LinkedObjectSet connectedObjects = target as LinkedObjectSet;
         if (connectedObjects.linkedObjects == null)
         {
             return;
         }
         Vector3 center = connectedObjects.transform.position;
         for (int i = 0; i < connectedObjects.linkedObjects.Length; i++)
         {
             GameObject connectedObject = connectedObjects.linkedObjects[i];
             if (connectedObject)
             {
                 Handles.DrawLine(center, connectedObject.transform.position);
             }
         }
     }
 }

Script attached to each empty game object which contains the objects that should have a line drawn between them:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LinkedObjectSet : MonoBehaviour {
 
     public GameObject[] linkedObjects = null;
 }

The topic is addressed here, where the solution appears to be to use the Delegate function of SceneView. I gave that a try below:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(LinkedObjectSet))]
 class LinkedObjectLineDrawer : Editor
 {
     void OnEnable()
     {
         SceneView.onSceneGUIDelegate += this.OnSceneGUI;
     }
     void OnDisable()
     {
         SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
     }
     void OnSceneGUI(SceneView sceneView)
     {
         LinkedObjectSet connectedObjects = target as LinkedObjectSet;
         if (connectedObjects.linkedObjects == null)
         {
             return;
         }
         Vector3 center = connectedObjects.transform.position;
         for (int i = 0; i < connectedObjects.linkedObjects.Length; i++)
         {
             GameObject connectedObject = connectedObjects.linkedObjects[i];
             if (connectedObject)
             {
                 Handles.DrawLine(center, connectedObject.transform.position);
             }
         }
     }
 }

...but then receive a host of errors and a blank Scene view in the editors. Errors include:

TargetParameterCountException: parameters do not match signature (etc.) GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)

Which has left me out of my depths, especially as this seems to still be undocumented territory.

Thanks in advance if anyone can point me in the right direction!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Oct 10, 2018 at 12:42 AM

What you're doing here is of course wrong. The Editor class is only relevant when an object is selected. It actually receives the "OnSceneGUI" message which does not take any parameters. If you registrating a manual scene view callback you have to use a different name for that method. You can name it whatever you like, just not any of the built-in callback names.


Since you want a permanent line drawn, just use Gizmos. For those you don't need a seperate editor script. Inside a MonoBehaviour class you can define the OnDrawGizmos method.

Comment
Add comment · 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

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

132 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Editor Script Handles.Label problem. Labels don't move with gameobject 1 Answer

Showing Handles in the Game View 1 Answer

Drawing position handle from ScriptableObject editor. 2 Answers

Is it possible to determine wich Handles.PositionHandle is currently focused? 1 Answer

Using Handles.DrawAAPolyLine 1 Answer


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