Did you know that you can manipulate a game objects collider in the scene view by holding down the 'Shift' key. Holding shift will display the colliders control dots. Just drag the dots to adjust the collider!


Unity 101 Tip #11 - Snap to vertex

Published 6/17/2012 by createdbyx in News | Unity
Tags: ,

Hold the 'V' key while the translate tool is active and you can drag an object by it's vertices and snap that vertex to another objects vertex!


Unity 101 Tip #10 - Inspector lock

Published 6/16/2012 by createdbyx in News | Unity
Tags: ,

The inspector window contains a small lock icon in the top right of the window. If you select a game object and click the lock the inspector will be locked to that object and will not change when you select other objects. Click again to disable the lock. This allows you to have multiple instector windows open with locks to different objects.


To allow the user to undo actions that are performed by a custom editor script you can use Undo.RegisterUndo

foreach (var item in Selection.transforms)
{
    Undo.RegisterUndo(item, "Move " + item.name);
    var pos = item.position;
    pos = new Vector3(activeObject.transform.position.x, pos.y, pos.z);
    item.transform.position = pos;
}

If you want to take advantage of functionality that is provided my menu commands you can use EditorApplication.ExecuteMenuItem in your editor scripts to execute them.


Are you working on a large project but dislike how many objects you have to weed through in the hierarchy window? You can create editor scripts that change the objects Object.hideFlags property to hide or show the object in the hierarchy window.

var item = Selection.activeGameObject;
if ((item.hideFlags & HideFlags.HideInHierarchy) == HideFlags.HideInHierarchy)
{
                item.hideFlags = item.hideFlags ^ HideFlags.HideInHierarchy;
                item.active = !item.active;
                item.active = !item.active;
}

Notice that item.active = !item.active is specified twice. Currently in unity 3.5 you need those 2 lines of code for the game object to hide and show properly in the hierarchy window.


Wondering how to save player preferences across sessions or save settings for an editor script to use? Check out EditorPrefs & PlayerPrefs.


If you are writing custom editors for unity and you need to have a way of editing the tools settings you can have those settings show up in the Unity Preferences Window "Edit -> Preferences...".

Just create a new editor script that has a public class and add the fallowing lines of code ...

// Add preferences section named "cbxTools" to the Preferences Window
    [PreferenceItem("cbxTools")]
    public static void PreferencesGUI()
    {
        // Preferences GUI
        cbxToolPreferencesConfig.Instance.DrawGUI();
    }


If your suddenly finding that Unity will instanty terminate while running your code, check if you are invoking any infinite recusion loops. This has recently happened to me and it was a bit of a pain to track down with Unity 3.5 instantly terminating. Hopfully the Unity team will handle the infinite recustion issue in a future version.


You can visually tag your game objects with icons by selecting the object and clicking the Red/Green/Blue colored cube in the upper left of the inspector window.

You can select a colored Label, Dot, or a Texture from your assets.


Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume