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. Dismiss Notice

Unofficial Package for Entity Picking (SceneView Selection)

Discussion in 'Entity Component System' started by Jonas_DM_, Oct 13, 2019.

  1. Jonas_DM_

    Jonas_DM_

    Joined:
    Feb 28, 2019
    Posts:
    22
    I made a simple (but effective) solution for selecting entities in the Unity SceneView.
    The goal was to make it as simple to install as possible, so it's become a package.
    You can find all info here: https://github.com/JonasDeM/EntitySelection



    Until we get official entity picking, this might be usefull for people working with DOTS.
    Feel free to post feedback.

    Cheers
     
  2. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    909
    Awesome man! Thanks for sharing.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    I haven't tested but looks neat :)
     
  4. Jonas_DM_

    Jonas_DM_

    Joined:
    Feb 28, 2019
    Posts:
    22
    Small update,
    Improved "How to select" in the readme.
    Added a green wirecube gizmo around selection.
    upload_2020-1-12_17-52-36.png
     
    JesOb and jdtec like this.
  5. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    297
    Would be really nice to see this functionality have official support soon. And the ability to see DOTs physics colliders at runtime!
     
  6. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    If I understand you correctly, you can have that already:

    Code (CSharp):
    1.             // Physics debug system.
    2.             var entity = entityManager.CreateEntity();
    3.             entityManager.SetName(entity, "PhysicsDebugDisplayData");
    4.             entityManager.AddComponentData<PhysicsDebugDisplayData>(entity, new PhysicsDebugDisplayData()
    5.             {
    6.                 DrawBroadphase = 0,
    7.                 DrawColliders = 1,
    8.                 DrawColliderAabbs = 1,
    9.                 DrawColliderEdges = 1
    10.             });
    So, just create an entity once with the above component (can be configured differently, of course).
     
    Last edited: Jan 15, 2020
    Silloty and jdtec like this.
  7. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    297
    Excellent thanks!
     
  8. Jonas_DM_

    Jonas_DM_

    Joined:
    Feb 28, 2019
    Posts:
    22
    Version 0.2.0 is out!
    Massive performance/memory improvements by using MaterialPropertyBlocks.
    Removed all non editor classes. (This required increasing the min unity version to 2019.3)

    2019.2 is still supported by a new 2019.2 branch (See Readme), but there's no WireCube to indicate selection.
     
    Silloty likes this.
  9. Silloty

    Silloty

    Joined:
    Jan 8, 2018
    Posts:
    21
    Hi

    Is it normal that this works only displaying one collider and not more ?

    Thanks a lot

    Great job !
     
  10. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Does it require some component for it to work? Like what if I'm using DrawMeshInstanced() so entities don't have any bounding box information.
     
  11. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    I call this trick pixel perfect picking based off this post from 2017 where I first saw it: https://medium.com/@philippchristoph/pixel-perfect-selection-using-shaders-16070d3094d

    But to answer your question the implementation in this post requires RenderMesh and LocalToWorld. However if you implement the technique yourself you can do it with whatever components you use, it just fills a CommandBuffer with mesh data.

    The idea is just to basically render the scene again giving every mesh a custom flat material with a different color. Then you simply query the color of the pixel your cursor under and you check which mesh that is.
     
    Egad_McDad, davenirline and jdtec like this.