Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

In-Editor Collision Detection

Discussion in 'Editor & General Support' started by vladisbecker, May 22, 2022.

  1. vladisbecker

    vladisbecker

    Joined:
    Jul 13, 2019
    Posts:
    3
    Hello,

    I am currently working on an In-Editor tool which given some area constraints is meant to populate a space with assets. I can add any kind of manual extent representation like a collider to the assets if necessary. These objects should be randomly placed and then checked for collisions. If a collision is happening, I want to revert the placement and try again. All of this must run in the editor and not while the game is running.

    My understanding is that typical collision detection in Unity is dependent on the Physics processes running, which in turn requires the game to be running. This is naturally not given with my script, which uses the ExecuteAlways attribute and is executed in the editor. I don't require anything necessarily event based, as a one-time check between two objects to see if they collide would be sufficient.

    What options do I have for this? In the worst case, I might switch to an in-game implementation of my approach, but would very much prefer the in-editor approach.
     
  2. pixaware_pwedrowski

    pixaware_pwedrowski

    Joined:
    Oct 25, 2018
    Posts:
    116
  3. vladisbecker

    vladisbecker

    Joined:
    Jul 13, 2019
    Posts:
    3
    I do believe that this is largely equivalent to the ExecuteAlways attribute I have been already using. I originally found ExecuteAlways when looking up ExecuteInEditMode.

    Can you maybe give me an example of how I would use an ExecuteInEditMode script to check the collision between two assets which both have some kind of collider? Or possibly another type of collider-like component? There doesn't seem to be anything like an IsTouching method for 3D colliders that works without event based collision processing and in the editor, I wouldn't know how to use event based collision detection like with the OnCollisionEnter and OnCollisionExit methods.