UnityLock is a new editor utility that lets you lock game objects in your scene. When an object is locked it can’t be moved or deleted, no components can be added or removed, and no existing components can be modified. Please note that this is an editor extension only; locked objects are fully editable at runtime via scripts. UnityLock only prevents modification of objects inside the editor.
There are lots of times when you may want to make an object un-editable - and now you can.
If you have static level geometry placed where you want it, just lock it to prevent accidentally moving or deleting it.
If you have game objects that are singleton or “manager” type objects, now you can configure their components and then lock them to prevent them from being deleted or moved around the scene.
If you just need to temporarily prevent an object from being modified while you work around it just quickly lock it, do your work, and then unlock the object.
Personally I thought it was a bit weird that Unity didn’t already have a lock button. For example in tools like Photoshop it can be quite helpful to lock layers to prevent them from being edited. It lets you isolate your editable state and make sure you’re only affecting things you want. This asset adds that functionality to Unity in an extremely simple way.
UnityLock adds a menu under GameObject where you’ll find all the functionality:
Additionally, as you can see, there are keyboard shortcuts for the two common operations which lock or unlock a game object and all of its children. This makes working with UnityLock a lot simpler than having to always use the menu.
When locked, the object’s inspector will be all disabled and, in Unity 4, the “Add Component” button is no longer present. This lets you quickly tell that the object is locked.
Updates:
Nov 2 - Version 1.1 is available and includes some cool new features. See this post for the details.
UnityLock is available for free! on the Asset Store: u3d.as/content/nick-gravelyn/unity-lock/3v5
I’m also adding in support for undo/redo as I’ve found without it you can get into weird situations. Consider this series of events:
Move an object.
Scale an object.
Lock an object.
Hit undo 3 times.
One might expect to undo the move and scale, but since the lock wasn’t in the undo stack the object remains locked and thus the undos for the scale and move silently do nothing. Now the lock/unlock operations are in the undo stack so in the case above you’ll first undo the lock, then undo the scale, and then the move, just like one would expect.
I also have found a way to suppress most selections in the scene view. There doesn’t seem to be a way to stop selection rectangles on objects with meshes, however I’ve found a way to suppress all standard left click selection as well as selection rectangles over objects like lights and cameras which have no mesh representation.
It definitely helps, especially if you’ve got a lot of static level meshes you want to lock. If you drag a selection rectangle you might hit them, but just left clicking in the scene will no longer select them.
Lastly I’m adding a preferences window under Window->UnityLock Preferences to control all three of these changes so that users can customize it how they want.
I will be submitting this update tonight so it should be available soon.
Lock state on prefabbed objects resets after every unity restart, making this add-on almost useless for heavy prefabs users. And it wasn’t mentioned in the description.
After buying a copy of UnityLock, I re-wrote a considerable amount of it to change the interface a bit and also allow locking to persist through prefab changes. Though being that part of the original code belongs to a paid product, I’m not quite sure on the etiquette for releasing it.
Sorry for the lack of replies; been busy with work and starting my own company.
I’ve made the asset free on the store because of my lack of time to properly support it. I never had time to investigate fixes for the prefabs because I wasn’t using them a lot in my levels at the time. Now that this is a free asset, please feel free to share any code or modifications you’d like with each other to make it more useful.