Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 WillNode · Dec 15, 2015 at 12:17 PM · editormeshscene view

Make Graphics.DrawMesh clickable at scene editor

Hi, basically i want to make a fully customized procedural mesh for my project, so instead of using MeshFilter component, i'm using Graphics.DrawMesh for fulfilling my needs.

 [ExecuteInEditMode]
 public class MyMesh : MonoBehaviour
 {
    void Update()
    {
        Graphics.DrawMesh(mesh,transform.localToWorldMatrix,material,0);
    }
 }

but here's the problem, since i'm not touching anything about MeshFilter and Graphics.DrawMesh only do the drawing of my mesh, the scene window will simply not recognize selection of this mesh (i.e. my mesh isn't selectable on scene window), so i only can select them from hierarchy window.

how i can make Graphics.DrawMesh selectable on scene view?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by WillNode · Dec 15, 2015 at 10:56 PM

waking up from my bed, and came-up with idea like this:

  public class MyMesh : MonoBehaviour
  {
    Mesh m; //Keep it private to not be included when instantiante
    void OnValidate()
    {
         UpdateMesh();
    }
     void Update()
     {
         UpdateMesh();
     }
     void UpdateMesh()
     {
           //Do rest of the procedural code here
           GetComponent<MeshFilter>().mesh = m;
      }
  }

this snippet code is solving to my specific case (already mention that in comment).

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
avatar image
1

Answer by drchilitopicoso · Aug 07, 2016 at 01:24 PM

You can use Gizmos, but not in the usual way. Use the [DrawGizmo()] attribute. You can pass it many types or options(check the documentation). I like to have a class placed in the Editor folder dedicated just for this.

 public static class EditorGizmos
 {
     [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.Pickable | GizmoType.Selected)]
     static void ExampleGizmo(TYPEOFACOMPONENT component, GizmoType type)
     {
         bool selected = (type & GizmoType.Selected) > 0;
          //You can make it always transparent if you want so it's not intrusive
         var col = new Color(0.0f, 0.7f, 1f, 1.0f);
         col.a = selected ? 0.3f : 0.05f;  //change color when selected to highlight
         Gizmos.matrix = component.gameObject.transform.localToWorldMatrix;
         Gizmos.color = col;
         Gizmos.DrawCube(Vector3.zero, Vector3.one * someSizeOrTheScaleValueFromTransform);
     }
 
 }

Then you can simply click on the cube and the gameobject will be selected. When making custom stuff with Graphics.DrawMesh i recommend having a Bounds variable somewhere in the class so you can customize the selection area further if you want. Or use the bounds of the mesh.

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
avatar image
0

Answer by wibble82 · Dec 15, 2015 at 01:52 PM

I realise this isn't specifically an answer to your question, but why do you not want to use MeshFilter? You can still set the mesh that MeshFilter uses. I ask because that is without a doubt the simplest way to make it still selectable in unity.

Quick tutorial here just in case you'd missed the fact that this was possible:

http://blog.nobel-joergensen.com/2010/12/25/procedural-generated-mesh-in-unity/

If you want your mesh fully functional in the scene view then I would recommend this approach.

-Chris

Comment
Add comment · Show 1 · 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 WillNode · Dec 15, 2015 at 08:52 PM 0
Share

the reason why i'm avoiding the $$anonymous$$eshFilter Simply because:

  1. using mesh at edit mode will give you a warn about instantianting mesh at editor

  2. using shared$$anonymous$$esh will be a trouble if you duplicating object in editor (the mesh isn't instantiated along with $$anonymous$$eshFilter)

  3. There is no way to tell you if the mesh are has been instantiated

  4. (maybe bit off) i see Text$$anonymous$$esh isn't using $$anonymous$$eshFilter to do that job

maybe you can figuring out how to solve these problems, anyway i appreciate your time here.

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

35 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

Related Questions

Make procedural mesh show in Scene Editor, not just in "Play" mode 5 Answers

Get input from a Xbox controller in an editor script, in editor mode (when Application is NOT running) 0 Answers

Why do mobile particle shaders look bad in game view but not in scene view? 1 Answer

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

Colored Voxel Meshs 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