- Home /
Ho do I find all scenes with a certain script on an GameObject
I want to find all scene that a particular MonoBehaviour on any GameObject. My first plan was to convert all scenes to text serialization and do text search, but That always crashes my Editor with a request for an addition 16GB of ram to convert a Texture2d. Any other methods maybe using AssetDatabase to search Scenes?
I am porting a project with limited support from original code.
500+ scenes.
C# but I don't see why the language matters.
I am just trying to find them in the editor.
I change the serialization on a smaller project to Force text and looked a the .unity files. In those I can see the GUID for each monobehaviour attached to an object. with AssetDatabase.GUIDToAssetPath or AssetDatabase.AssetPathToGUID depending which your going I could find out what Scripts are used in each scene. At worst I could do a quick text search from outside unity. I was hoping to get the information visible in a .unity file when saved as text from AssetDatabase calls.
This seems to be more trouble than it's worth. Why do you want to do this? Is there not a simpler solution?
Which program$$anonymous$$g language are we talking about?
Are you just trying to find them for editing or are you trying to do this at runtime in your actual game?
Answer by airship-brooks · Nov 10, 2015 at 05:37 PM
If you have .meta files turned on, you can open the script's meta file in a text editor and see what the guid is for the script there. You can search for that guid in all your .unity and .prefab files in a text editor.
Also in project settings > Editor you need to have asset serialization mode set to "force text" I think. That is how I do it now. When I post my question there was bug in version of Unity (a console specific version) I was using that stopped my from switching to force text mode.
on Linux with ter$$anonymous$$al this works perfect
$ grep -Rni guid
thanks
Answer by abdulthegamer · Jul 24, 2014 at 08:18 AM
Hi Ryuuguu,
Sorry to say but there is no way that you can find certain script on GameObeject in any of the scenes in project. Except that you should remember it or check each object and some script may be instatiated.
If you got that then mark this as answer and close this.
Regards.
In editor, it is possible, you can load a scene, get all objects, get the components into a static array or a file, then load next scene and so on.
Is it worth it? I don't know.
This is how assets on the store do this , it is very slow with large projects.
So yes, it is possible if you want it.
[$$anonymous$$enuItem ("EditorScript/EditorTest %t",false, 0),]
private static void EditorTest ()
{
List<Script> list = new List<Script>();
string [] sceneNames = new string[]{"Level1", "Inventory", "$$anonymous$$enu"};
foreach(string sceneName in sceneNames){
EditorApplication.OpenScene(sceneName);
GameObject [] objs = FindObjectsOfType<GameObject>();
foreach(GameObject obj in objs){
Script script = obj.GetComponent<Script>();
if(script != null){
list.Add(script);
}
}
}
}
This in a editor script. You would have to do something with the list at the end.