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 /
  • Help Room /
avatar image
1
Question by neo_nille · Feb 05, 2016 at 02:35 PM · vertexsnappinggaps

Vertex snapping does not work properly.

Whenever i want to use the vertex snapper it always leaves a tiny gap between the two objects. Like this: http://i.imgur.com/1ghdERF.png To fix it i have to zoom in and use the snapper again. It's extremely annoying and adds a tremendous amount of tedious extra work. Any fixes?

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
4

Answer by Feelnside · Jan 23, 2018 at 01:49 PM

Looks like I found out the solution. I'm using the latest version of Unity (2017.3.0p3). In the top left corner select the new tool system (Move Rotate or Scale selected objects)

alt text

With this system I can successfully align the meshes using Vertex Snap Tool ('V' button). With simple 'Move Tool' I have the same issue as the topic starter. I hope this helps.


1tool.png (22.3 kB)
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 jeremyinteractive · Aug 30, 2018 at 09:41 PM 0
Share

I'm using Unity 2018.1.9f2 and this solved my problem. Thanks.

avatar image unity-marcus · Jan 05, 2020 at 02:20 PM 0
Share

Still broken (again) in Unity 2019.3.0f3. Your workaround with the move/rotate/scale tool helped me a lot. Thanks

avatar image
1

Answer by andranik87 · Apr 29, 2016 at 10:24 PM

I am having the same problem here too. In some parts of the vertex snapped planes and cubes, I get gaps like thesealt text

alt text

Any one know how to fix these?


untitled2.png (150.7 kB)
untitled1.png (387.6 kB)
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 Nullmind · Jan 07, 2018 at 02:07 PM

Had the same problem.
Please, do vote this issue here so we can get a faster fix.

For now I'm using this VertexSnap script which works nicely when you press 'C' key:

 using System.Collections.Generic;
 using UnityEngine;
 
 #if UNITY_EDITOR
 using UnityEditor;
 
 [InitializeOnLoad]
 public class MyVertexSnap {
     private static MyVertexSnap instance;
 
     private bool inSnapMode;
     private bool inSnapMove;
     private MeshFilter snapMesh;
     private int snapVertexIndex;
     private List<Transform> selectedTransforms;
 
     static MyVertexSnap() {
         if (instance == null) instance = new MyVertexSnap();
     }
 
     public static MyVertexSnap GetInstance() {
         if (instance == null) instance = new MyVertexSnap();
         return instance;
     }
 
     private MyVertexSnap() {
             inSnapMode = false;
             inSnapMove = false;
             snapMesh = null;
             snapVertexIndex = 0;
             selectedTransforms = new List<Transform>();
             SceneView.onSceneGUIDelegate += HandleOnSceneGUI;
         }
 
         ~MyVertexSnap() {
             SceneView.onSceneGUIDelegate -= HandleOnSceneGUI;
         }
 
     private void HandleOnSceneGUI(SceneView sv) {
         Event e = Event.current;
 
         if (e.isKey) {
             if (e.type == EventType.KeyDown) {
                 if (e.keyCode == KeyCode.C) {
                     if (Tools.current == Tool.Move) {
                         if (!inSnapMode) {
                             this.FindTransforms();
                             this.FindVertex();
                             inSnapMode = true;
                             inSnapMove = false;
                         } else {
                             inSnapMode = true;
                         }
                     }
                 }
             } else if (e.type == EventType.KeyUp) {
                 if (e.keyCode == KeyCode.C) {
                     if (inSnapMode) {
                         Undo.FlushUndoRecordObjects();
                         GUIUtility.hotControl = 0;
                         inSnapMode = false;
                         inSnapMove = false;
                     }
                 }
             }
         } else if (e.isMouse) {
             if (inSnapMode) {
                 if (e.type == EventType.MouseMove) {
                     if (!inSnapMove) {
                         GUIUtility.hotControl = GUIUtility.GetControlID(118473327, FocusType.Passive);
                         this.FindVertex();
                     }
                 } else if (e.type == EventType.MouseDrag) {
                     GUIUtility.hotControl = GUIUtility.GetControlID(118473327, FocusType.Passive);
                     if (inSnapMove) this.SnapVertex();
                 } else if (e.type == EventType.MouseDown && e.button == 0) {
                     GUIUtility.hotControl = GUIUtility.GetControlID(118473327, FocusType.Passive);
 
                     if (!inSnapMove) {
                         this.FindVertex();
                         inSnapMove = true;
                         GameObject[] recordedObjs = new GameObject[selectedTransforms.Count];
                         int i = 0;
 
                         foreach (Transform t in selectedTransforms) {
                             recordedObjs[i] = t.gameObject;
                             i++;
                         }
 
                         Undo.RegisterCompleteObjectUndo(recordedObjs, "My Vertex Snap");
                     }
                 } else if (e.type == EventType.MouseUp && e.button == 0) {
                     Undo.FlushUndoRecordObjects();
                     GUIUtility.hotControl = 0;
                     selectedTransforms = new List<Transform>();
                     inSnapMode = false;
                     inSnapMove = false;
                     snapMesh = null;
                 }
             }
         }
     }
 
     private void FindTransforms() {
         selectedTransforms = new List<Transform>(Selection.GetTransforms(SelectionMode.Unfiltered));
     }
 
     private void FindVertex() {
         snapMesh = null;
         snapVertexIndex = 0;
         Plane cameraPlane = new Plane(
             Camera.current.transform.position,
             Camera.current.transform.position + Camera.current.transform.right,
             Camera.current.transform.position + Camera.current.transform.up
         );
         Event e = Event.current;
         Vector3 mousePos = new Vector3(e.mousePosition.x, Camera.current.pixelHeight - e.mousePosition.y, 0);
         float searchDist = 20.0f;
 
         foreach (Transform t in selectedTransforms) {
             MeshFilter meshFilter = t.GetComponent<MeshFilter>();
 
             if (meshFilter != null) {
                 Mesh mesh = meshFilter.sharedMesh;
 
                 if (mesh != null) {
                     Vector3[] vertices = mesh.vertices;
 
                     for (int i = 0; i < vertices.Length; i++) {
                         Vector3 v = vertices[i];
                         Vector3 worldPos = meshFilter.transform.TransformPoint(v);
 
                         if (cameraPlane.GetSide(worldPos)) {
                             Vector3 vertexScreenPos = Camera.current.WorldToScreenPoint(worldPos);
                             vertexScreenPos.z = 0;
                             float dist = (vertexScreenPos - mousePos).magnitude;
 
                             if (dist <= searchDist) {
                                 searchDist = dist;
                                 snapMesh = meshFilter;
                                 snapVertexIndex = i;
                             }
                         }
                     }
                 }
             }
         }
     }
 
     private void SnapVertex() {
         Plane cameraPlane = new Plane(
             Camera.current.transform.position,
             Camera.current.transform.position + Camera.current.transform.right,
             Camera.current.transform.position + Camera.current.transform.up
         );
         Event e = Event.current;
         Vector3 mousePos = new Vector3(e.mousePosition.x, Camera.current.pixelHeight - e.mousePosition.y, 0);
         MeshFilter[] meshFilters = Object.FindObjectsOfType<MeshFilter>();
         Vector3 snapPos = Vector3.zero;
         bool doSnap = false;
         float searchDist = 20.0f;
 
         foreach (MeshFilter m in meshFilters) {
             if (selectedTransforms.Contains(m.transform)) continue;
             if (!m.gameObject.activeInHierarchy) continue;
 
             if (m != null) {
                 Mesh mesh = m.sharedMesh;
 
                 if (mesh != null) {
                     Vector3[] vertices = mesh.vertices;
 
                     for (int i = 0; i < vertices.Length; i++) {
                         Vector3 v = vertices[i];
                         Vector3 worldPos = m.transform.TransformPoint(v);
 
                         if (cameraPlane.GetSide(worldPos)) {
                             Vector3 vertexScreenPos = Camera.current.WorldToScreenPoint(worldPos);
                             vertexScreenPos.z = 0;
                             float dist = (vertexScreenPos - mousePos).magnitude;
 
                             if (dist <= searchDist) {
                                 searchDist = dist;
                                 snapPos = worldPos;
                                 doSnap = true;
                             }
                         }
                     }
                 }
             }
         }
 
         if (doSnap) {
             Vector3 originalPos = snapMesh.transform.TransformPoint(snapMesh.sharedMesh.vertices[snapVertexIndex]);
 
             if (!originalPos.Equals(snapPos)) {
                 Vector3 offset = snapPos - originalPos;
 
                 foreach (Transform t in selectedTransforms) {
                     t.gameObject.transform.position += offset;
                 }
             }
         }
     }
 
     public void HandleOnSceneGUIDrawing() {
         if (inSnapMode) {
             Vector3 cameraPos = Camera.current.transform.position;
             Quaternion cameraRot = Camera.current.transform.rotation;
 
             if (snapMesh != null) {
                 Vector3 vertexPos = snapMesh.transform.TransformPoint(snapMesh.sharedMesh.vertices[snapVertexIndex]);
                 float vertexDist = (cameraPos - vertexPos).magnitude;
 
                 if (inSnapMove) Handles.color = Color.red;
                 else Handles.color = Color.blue;
 
                 Handles.CircleHandleCap(0, vertexPos, cameraRot, 0.015f * vertexDist, EventType.Repaint);
             }
         }
     }
 }
 #endif


Also do not forget to place this VertexSnapEditor script inside your Editor folder:

 using UnityEditor;
 using UnityEngine;
 
 [CustomEditor(typeof(MeshFilter))]
 [CanEditMultipleObjects]
 public class MyVertexSnapEditor : Editor {
     public void OnSceneGUI() {
         MyVertexSnap vs = MyVertexSnap.GetInstance();
         vs.HandleOnSceneGUIDrawing();
     }
 }


Hope it helps.

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 Feelnside · Jan 23, 2018 at 01:29 PM 0
Share

I have the same issue. Tried to resolve it using your scripts: I have created two C# scripts ($$anonymous$$yVertexSnap and $$anonymous$$yVertexSnapEditor) both these scripts located inside the Editor folder (Assets/Editor) but it's not working. trying to press 'C' and nothing. Could you please clarify am I missed something?

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

45 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

Related Questions

Vertex snapping results in small noticable gap 0 Answers

Vertex Snapping - The Question Remains 0 Answers

[Unity 2017.1] Gaps/Overlapping with Vertex Snapping Tool 1 Answer

Can I attach a grid to a moving GameObject? 0 Answers

Should I use a shader or conventional code for displacement? 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