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.

How do I lock a mesh or make it unselectable?

Discussion in 'Editor & General Support' started by 3Dnut, Dec 30, 2009.

  1. 3Dnut

    3Dnut

    Joined:
    Nov 20, 2009
    Posts:
    21
    I would like to know if there is some way in Unity to mark a mesh as locked or unselectable so that during population of items I don't keep grabbing and sometimes accidentally moving the terrain. Anyone know if this is possible and how to go about doing it if it is?

    Thanks in advance for your help,

    3Dnut
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Unfortunately you cannot "lock" game objects in Unity.
     
  3. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    If you have a mesh that annoying you well working on another I often just turn off its mesh renderer. Then you can not select it by accident.

    Turn it back on later when your done. Works like a charm.
     
  4. 3Dnut

    3Dnut

    Joined:
    Nov 20, 2009
    Posts:
    21
    Well I can't say that I am too thrilled with the lack of that functionality, but maybe it will get added in the future. I am, however, very grateful to have seasoned Unity users like yourself who take the time to answer questions. Thanks!
     
  5. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    The lack of a lock is fairly annoying once you have lots of geometry, but it should be possible to fake some of that functionality with editor scripts and a specialized component or so.
     
  6. BetaRayBill

    BetaRayBill

    Joined:
    Jun 6, 2009
    Posts:
    188
    I was going to ask for this too (lock button next to object) Instead I've been doing everything in Maya, and locking it there and re exporting. Little workaround, but it works.
     
    klesun likes this.
  7. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Ok, wrote a script to do it on my end; it's apparently almost built-in to unity, just not exposed. Can't post entire script as it's mixed up with other stuff, but the code looks roughly like this:

    Code (csharp):
    1.  
    2.         if (GUILayout.Button("Lock"))
    3.         {
    4.             if ((int)Selection.activeGameObject.hideFlags == 0)
    5.             {
    6.                 Selection.activeGameObject.hideFlags = HideFlags.NotEditable;
    7.             }
    8.         }
    9.  
    10.         if (GUILayout.Button("Unlock"))
    11.         {
    12.             if (Selection.activeGameObject.hideFlags == HideFlags.NotEditable)
    13.             {
    14.                 Selection.activeGameObject.hideFlags = (HideFlags)0;
    15.             }
    16.         }
    17.  
    Put it in an editor window somewhere.
    You can still select the level by accident, but you won't be able to move it and all the properties will be grayed out.
     
  8. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    When things like this come up I strongly encourage you to use your voice here:

    http://feedback.unity3d.com

    It's a place where you can go log feature requests, or vote for others you find interesting (you have limited votes so use them wisely!). Please understand that we won't be slaves to this list in any way, but we will use it as a solid source of feedback about where the product needs change and improvement so add your thoughts!


    BTW, I get the sentiment here, locking of items would be nice indeed. Don't confuse my factual response with a lack of understanding. :)
     
  9. Bluestrike

    Bluestrike

    Joined:
    Sep 26, 2009
    Posts:
    256
    using Cannons ecample,
    causes a expecting a semicilon error in uniscript.
    Any way to make that work?
     
  10. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    2,071
    Just to crosslink Bluestrikes question

    Btw, this will preserve other hideflags:
    Code (csharp):
    1.  
    2.     if (GUILayout.Button("Toggle Lock"))
    3.     {
    4.          Selection.activeGameObject.hideFlags ^= HideFlags.NotEditable;
    5.     }
    6.  
     
    Last edited: May 21, 2012
  11. TruffelsAndOranges

    TruffelsAndOranges

    Joined:
    Nov 9, 2014
    Posts:
    92
    Thanks! I was looking for something like this. Will see if I can get it working.
     
  12. orihq

    orihq

    Joined:
    May 25, 2016
    Posts:
    7
    If it is a button, deselect "Interactable" in the inspector.
     
  13. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    570
    You can still select "NotEditable" objects mesh, very nice and "useful" feature.
     
unityunity