Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    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:
    685
    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:
    685
    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:
    685
  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:
    685
    That's beyond my capabilities. The above solution is good enough for me so I've never tried to find something better.