- Home /
References of objects/classes in scenes NOT open in the scene view
I need to be able to find object and class references in scenes that aren't open in the scene view. I know that in 3.5 scenes are text based, but I'm wondering if anyone knows of a search tool / utility that already does this or how it can be done currently?
I have the ability to right click on a class and choose "Find references in scene", which looks in the currently opened scene, or even use "select dependencies" on items in the project view. I've even tried copying the search string that "Find references in scene" creates and used that in the project search bar - this doesn't work unfortunately.
But what I'm after is the ability to right click or select a class and "find references in all objects in project including unopened scenes".
This would be massively helpful :) We have 70 scenes currently, you can imagine the hassle while doing localization.
We have 70 scenes currently, you can imagine the hassle while doing localization
You should think of an automatic system for localization, not involving changing by hand all your scripts/objects.
By the way scene are not text-based if you don't have PRO or if the settings for asset serialization is on 'Binary' or '$$anonymous$$ixed'.
yes, we wrote the localization library after the app was written unfortunately for me. I have to go through now and retro fit :(
Answer by Kryptos · Apr 06, 2012 at 05:10 PM
You can write an EditorWindow script and use the editor utilities to open/close each scene one after another and list all found objects in this window.
Read the documentation.
http://unity3d.com/support/documentation/ScriptReference/EditorWindow.html
http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.html
http://unity3d.com/support/documentation/ScriptReference/EditorUtility.html
http://unity3d.com/support/documentation/ScriptReference/EditorApplication.html
Particularly EditorApplication.OpenScene()
will be useful.
yeah, i was close to getting started on doing this, I just wanted to find out if there was (1) already a tool out there that did this work already (2) there was already a way in the editor to do this.
Sounds like there's not ;)
Answer by GingerLoaf · May 23, 2014 at 10:08 PM
Kryptos gave a very good answer due to the fact that he is asking unity to give him the information he wants, however his solution can become very slow depending on project size. Loading large scenes one after the other can take a lot of time. It also requires that you are in unity (you can't make a shell script to do the work or something). I've found that I can ask AssetDatabase to hand over the GUID for the script I want to search for by using "AssetDatabase.AssetPathToGUID("/.cs");" (or alternatively, opening the .meta file if you are forcing serialization to text), and then open up each .unity file and parsing it for the information I want. A good example is an editor utility script that could list off all the unopened scenes that contain the script of your choice:
Call AssetDatabase.AssetPathToGUID and pass in the script you want, then save the returned GUID in a variable.
Iterate through every scene file, or maybe just the scenes that are checked off in the build settings (accessible through EditorBuildSettings.scenes) to reduce it down to only the production scenes.
check if the text for each scene contains your GUID, and if so, hang onto the scene name for reporting.
Print out a nice list of scenes that contained your script.
You can do more advanced things using this method too, you just have to deal with the crazy nature of the YAML file.
It is very important to mention that this only works for scene files serialized as text, not binary. Also, making assumptions or dependencies on the YAML can lead to issues if unity every changes to something else or modifies the way they output information.
It's hacky, but faster.
Just wanted to share my thoughts :)
Find Reference 2 does exactly what @GingerLoaf suggested, read YA$$anonymous$$L files to get the GUIDs relationship and display in a panel