1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

How do I make a gameobject snapped to my path in edit mode?

Discussion in '2D' started by elgauly, Mar 18, 2017.

  1. elgauly

    elgauly

    Joined:
    Jun 26, 2016
    Posts:
    47
    Let's say I have a script called CircularPath, this path is a circle shape path which has radius, center point and angle variables. The angle variable specifies where the object is on the circle circumference. Now, if I create the path object which holds the CircularPath script and I create a game object which I want it move in the path, I want the game object to be snapped to it's rightful position already in the editor mode and not only in play mode then how do I do it?



    I tried using the attribute ExecuteInEditMode but it doesn't good for my need.

    I hope someone can help me with that,

    Thank you in advance.
     
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    652
    I quick and easy way I do this stuff is to hijack the OnDrawGizmos() function.
     
  3. elgauly

    elgauly

    Joined:
    Jun 26, 2016
    Posts:
    47
    I know how to draw the path. I'm only trying to understand how to move the game object to snap into the path while in edit mode, do you know how to do that?
     
  4. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    652
    What is the problem you're having exactly? Getting the nearest path position? Or getting the editor to run the code to snap the object to the correct location?
     
  5. elgauly

    elgauly

    Joined:
    Jun 26, 2016
    Posts:
    47
    Getting the editor to run the code to snap the object to the correct location BUT in edit mode.
     
  6. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    652
  7. elgauly

    elgauly

    Joined:
    Jun 26, 2016
    Posts:
    47
    It actually works :) but the object will snap into the right position only if the scene view window is focused (only when I click on the scene window) it's because the function OnDrawGizmos() is called only when the scene window is focused.
    I wonder how would you do this with custom editor?
     
  8. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    652
    That's beyond my capabilities. The above solution is good enough for me so I've never tried to find something better.