How to nicely select item in the Unity’s two-column Project Browser

Hey, I’ll try to be short.
I’m working on the Maintainer‘s Issues Finder improvements and one of such improvement was to select (show) the scene file at the Project Browser along with target GameObject in the Hierarchy when user press “Show” next to the found issue.

At the first iteration, I did the selection using Selection.objects and it worked great with One-column view mode of the Project Browser.
But things get weird when I switched to the two-column mode: target scene file still get selected, but it didn’t show up until I manually navigated to the folder with that file.

And surprisingly, I faced two common issues here:
1. Unity has no API to let you know in which mode the Project Browser is.
2. Unity has no API to select specific folder in the first column of the Project Browser.

But thankfully, we have ILSpy and reflection! ;)
So, using ILSpy I managed to find all what I need;
UnityEditor.ProjectBrowser class
– static s_LastInteractedProjectBrowser field to access last used ProjectBrowser window (we can have lot of ProjectBrowsers in Unity layout).
– private field m_ViewMode of the ViewMode enum type which has two values – OneColumn (0) and TwoColumns(1)
– private ShowFolderContents() method which expands first column of the TreeView to the specified folder and selects it

And here is a resulting code which selects both object in scene hierarchy and scene file in Project Browser in any column mode (one or two columns):

public void SelectObjectAndScene(GameObject targetGameObjectInScene, string scenePath)
	List<Object> selection = new List<Object>();

	Object sceneFile = AssetDatabase.LoadAssetAtPath(scenePath, typeof(Object));

	Type projectBrowserType = Type.GetType("UnityEditor.ProjectBrowser,UnityEditor");
	if (projectBrowserType != null)
		FieldInfo lastProjectBrowser = projectBrowserType.GetField("s_LastInteractedProjectBrowser", BindingFlags.Static | BindingFlags.Public);
		if (lastProjectBrowser != null)
			object lastProjectBrowserInstance = lastProjectBrowser.GetValue(null);
			FieldInfo projectBrowserViewMode = projectBrowserType.GetField("m_ViewMode", BindingFlags.Instance | BindingFlags.NonPublic);
			if (projectBrowserViewMode != null)
				// 0 - one column, 1 - two column
				int viewMode = (int)projectBrowserViewMode.GetValue(lastProjectBrowserInstance);
				if (viewMode == 1)
					MethodInfo showFolderContents = projectBrowserType.GetMethod("ShowFolderContents", BindingFlags.NonPublic | BindingFlags.Instance);
					if (showFolderContents != null)
						Object sceneFolder = AssetDatabase.LoadAssetAtPath(Path.GetDirectoryName(scenePath), typeof(Object));
						showFolderContents.Invoke(lastProjectBrowserInstance, new object[] { sceneFolder.GetInstanceID(),  true});
						Debug.LogError("Can't find ShowFolderContents method!");
				Debug.LogError("Can't find m_ViewMode field!");
			Debug.LogError("Can't find s_LastInteractedProjectBrowser field!");
		Debug.LogError("Can't find UnityEditor.ProjectBrowser type!");

	Selection.objects = selection.ToArray();

This code might be not elegant and clean since it’s a quick try to leave snippet in the blog. Feel free to correct my where I’m wrong.

P.S.: if you wish only show some file in the Project Browser without selection, just use EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(scenePath, typeof(Object))); It will work fine with one-column layout and will work with two-column layout if you don’t select anything else.

Share Button

Meet Maintainer Unity3D editor extension!

Maintainer logo

I’m glad to let you know I’ve released my new Asset Store contribution: Maintainer!
It’s going to be your best friend if you like to keep your projects clean and neat.

Currently it has one module: Issues Finder, but there will be more in future.
More details at


Share Button

Happy New Year 2015!

Hey dear readers and strangers!
This year was really great in many ways and I wish everyone to reach all goals, be healthy and closer to your family in new 2015 year.
Merry Christmas and Happy New Year!


Share Button

Unity3D Tweening performance

Hey, I’ll be short =)
I’m going to compare quickly 3 types of tween animations: built-in Legacy Animation, HOTween and DOTween.
I use 5k objects from prefabs as tweens targets.
Tweens are looped, start by default, have 1 sec length and tweening transform position from (0, 0, 0) to (1.3, 1.4, 1.5).

Used software info:
– Unity 4.6 Beta 16.
– HOTween v1.3.350.
– DOTween 0.7.310 Alpha
– Unity profiler with ‘Deep Profile’ enabled.

Initialization resources usage

Let’s compare initialization time and GC allocations first.
Time + GC Allocation + real memory allocation. Time is frame total time. Memory usage includes memory used by objects.

Frame time: ~166.7 ms (from 3 samples)
GC Allocations: 97.8 KB
Total memory usage: ~20.07 MB (from 3 samples)
Frames to initialize: 1

Frame time: ~268.68 ms (from 3 samples) + ~55.62 ms (from 3 samples) for second frame
GC Allocations: 4293 KB + 1.3 KB for second frame
Total memory usage: ~25.1 MB (from 3 samples)
Frames to initialize: 2

Frame time: 122.86 ms (from 3 samples)
GC Allocations: 1800 KB (may be kept away from GC using internal pooling)
Total memory usage: ~10 MB (from 3 samples)
Frames to initialize: 1

Resources usage per frame

Now tweening performance, allocations per frame (excluding constant Unity-releated allocators) and total memory usage while running tweens (memory usage increases for a while after initialization).
Time is frame total time.

Frame time: 12-13 ms
GC Allocations: 0 B

Frame time: 36-40 ms
GC Allocations: 420 B – 672 B (sad face here)

Frame time: 9 ms
GC Allocations: 0 B

Resulting charts

CPU time, ms (lower is better)

Memory usage on initialization, MB (lower is better)

Brand new DOTween gets the best Unity tweening solution award from me!
And it’s free, very flexible, user-friendly and has a great author. It definitely desires donation!

Grab messy benchmark sources (should be compatible with Unity 4.5) here.

Share Button

How to run your Unity3D app at Windows Phone 8 Emulator in VMWare


Here is a quick “how to set up” notes to myself and other curious people who have no Windows Phone device on the desk:

1. PC should be compatible with HYPER-V.
Hardware requirements: 64-bit processor with Intel VT or AMD-V support. DEP, Intel XD bit (execute disable bit) or AMD NX bit (no execute bit) should be enabled.
Software requirements: Pro+ editions Win 7 / Win 8 / Win 8.1 – both guest (client) and host.
Read more: Hyper-V Overview Continue reading

Share Button