• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
15
Question by itos · Sep 04, 2013 at 08:57 PM · selectionlock

How do I lock an object from selection

In other programs like Photoshop, After Effects, 3dsmax, Maya you can lock objects or layers so you don't select them by error when working in the viewport. I want to lock my background in my 2D game.

I have tried a temporal solution to turn off the Mesh renderer from the object. (but is not exactly a lock from selection since I can't view it anymore).

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
44
Best Answer

Answer by Magrippinho · Feb 11, 2014 at 07:48 PM

You've probably noticed by now, but Unity 4.3, released a couple of months after your question, added native Layer locking functionality!

The layers dropdown on the editor's toolbar (upper right) now has the familiar "layer visibility" and "layer lock" icons.


unitylayerlock.png (45.3 kB)
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Apr 01, 2015 at 04:12 PM 0
Share

This is a great solution to avoid accidental selection in the Scene view, but note that it doesn't prevent selection and editing from the Hierarchy panel.

avatar image TharosTheDragon · Sep 25, 2017 at 01:27 AM 1
Share

It's an imperfect solution because it only lets you lock by layer and not by object.

avatar image shieldgenerator7 · Nov 28, 2018 at 02:50 AM 0
Share

Thanks! This was exactly what I was looking for. However, it doesn't make much sense without the picture because I didn't even know that "Layers" button was up there until now.

avatar image walrys · May 08, 2019 at 09:48 AM 0
Share

I know this is an old thread, but does anyone know how to toggle layers programmatically? I'm looking for an editor script to do this

avatar image PixelFireXY walrys · Apr 05, 2020 at 01:39 PM 0
Share

What you were looking for is probably this: https://answers.unity.com/questions/760533/best-way-to-set-a-gameobject-layer-programmaticall.html

avatar image SmallLion · Dec 07, 2020 at 02:12 PM 0
Share

Thank you very much

avatar image
13

Answer by SolidAlloy · May 24, 2020 at 01:34 PM

There is a way to make a single object unselectable in Unity 2019.3 and newer. There is a hand icon to the left of an object in the hierarchy window. Clicking it toggles between blocking and allowing to select the object on the scene. More info at the following link, in the "Setting GameObject visibility and pickability section": https://docs.unity3d.com/Manual/Hierarchy.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image realbambiiyt · Aug 08, 2020 at 03:51 AM 1
Share

Thank you very much!

avatar image Gerark87 · Aug 11, 2020 at 06:20 PM 3
Share

This is definetely a better answer with the newest version of the editor.

avatar image Lttldude · Dec 05, 2020 at 05:08 AM 0
Share

Great solution, thank you.

avatar image Kaldrin · Feb 09, 2021 at 03:10 PM 0
Share

This is what I was looking for but while this is great, it doesn't persist after restarting the project :/

avatar image
2

Answer by CarlLee · Mar 12, 2021 at 03:08 AM

It's been a long time since the question has been asked. Just in case someone is still interested, there is a way to make object unselectable via click in scene. Simply add a pass with tag "LightMode" = "Picking" in your shader and discard its result instead of returning the correct _SelectionID. This is how Unity picks objects on screen fast.

     Pass
     {
         Name "Picking"
         Tags { "LightMode" = "Picking" }

         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_instancing
             #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
             #include "UnityCG.cginc"

             float4 vert(appdata_full v) : SV_POSITION
             {
                 UNITY_SETUP_INSTANCE_ID(v);
                 float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
                 return mul(UNITY_MATRIX_VP, worldPos);
             }

             uniform float4 _SelectionID;

             fixed4 frag() : SV_Target
             {
                 return _SelectionID;
             }
         ENDCG
     }

Add this pass to your shader, your object will be unselectable in SceneView, but still selectable in hierarchy window.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 12, 2021 at 11:22 AM 0
Share

That's actually a neat hacky solution. Until now I haven't really thought about how Unity does the object picking. However, does this also prevent selection through a selection rectangle? It not it's a half baked solution.

avatar image Kaldrin · Mar 12, 2021 at 12:43 PM 0
Share

Thank you I am very interested but I'm not quite sure I understand this solution, on which shader should we add this pass ?

avatar image
0

Answer by itos · Sep 04, 2013 at 09:31 PM

To answer my own question: I found an utility in the Unity Asset Store that does exactly what I want. You can lock objects so you can't edit them and also configure it in the preferences so you can't select them in the viewport. Also is free so anyone can use it. (I'm not affiliated or know the person that made the plugin).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FrimaMickD · Sep 04, 2013 at 09:07 PM

There is no built-in way to do this in Unity (or at least I'm not aware of it!) but you could always script it quite easily. Here is a link to another question that pretty much solve the same thing : http://answers.unity3d.com/questions/29346/lock-object-position-in-editor.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Global selection structure 1 Answer

How do I enlarge/zoom an object onMouseDown/Click? 1 Answer

Selectable GUI texts? 1 Answer

Button is not selectable when pressing the submit button even though it is highlighted. How do I fix that? 0 Answers

From Unity3d How to develop selection Mechanism for GearVR? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges