How do I lock a mesh or make it unselectable?

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

Unfortunately you cannot “lock” game objects in Unity.

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.

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!

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.

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.

1 Like

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:

        if (GUILayout.Button("Lock"))
        {
            if ((int)Selection.activeGameObject.hideFlags == 0)
            {
                Selection.activeGameObject.hideFlags = HideFlags.NotEditable;
            }
        }

        if (GUILayout.Button("Unlock"))
        {
            if (Selection.activeGameObject.hideFlags == HideFlags.NotEditable)
            {
                Selection.activeGameObject.hideFlags = (HideFlags)0;
            }
        }

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.

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. :slight_smile:

using Cannons ecample,

causes a expecting a semicilon error in uniscript.
Any way to make that work?

Just to crosslink Bluestrikes question

Btw, this will preserve other hideflags:

    if (GUILayout.Button("Toggle Lock"))
    {
         Selection.activeGameObject.hideFlags ^= HideFlags.NotEditable;
    }

Thanks! I was looking for something like this. Will see if I can get it working.

If it is a button, deselect “Interactable” in the inspector.

You can still select “NotEditable” objects mesh, very nice and “useful” feature.