I want to loop through all of my project’s scenes in a specific folder to figure out if they have certain GameObjects a player can collect. Super Metroid does this in a similar fashion, where it marks the location of items you can collect on a map. Then if you collect an item, its marked as collected.

I need to store the item location data inside a file or GameObject I can reference while the game is running. This should be doable from the Unity editor through a menu command.
I think this is what you want. If you need to be able to iterate through the scenes to gather the game objects while its running you’ll have to manage the play state manually using EditorApplication.isPlaying
.
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class GatherGameObjects {
public static List<string> GetScenes(string basePath = "") {
List<string> scenes = new List<string>();
foreach (UnityEditor.EditorBuildSettingsScene scene in UnityEditor.EditorBuildSettings.scenes) {
if (scene.enabled && scene.path.StartsWith(basePath)) {
scenes.Add(scene.path);
}
}
return scenes;
}
public static List<GameObject> GatherGameObjectsByTag(List<string> scenes, string tag) {
// The GO references probably go out of scope when the scene closes
// (You'll want to store something else like their absolute path in the hierarchy)
var gameObjects = new List<GameObject>();
// Save the current scene before attempting to open others
var safe = EditorApplication.SaveCurrentSceneIfUserWantsTo();
if (safe) {
foreach (var scene in scenes) {
EditorApplication.OpenScene(scene);
// If you want to use different criteria try Object.FindObjectsOfType<GameObject>()
// I don't think this includes inactive but maybe that doesn't matter
gameObjects.AddRange(GameObject.FindGameObjectsWithTag(tag));
}
}
return gameObjects;
}
[MenuItem("GameObject/Gather Collectible GameObjects")]
public static void GatherCollectibleGameObjects() {
var scenes = GetScenes("Assets/");
var gameObjects = GatherGameObjectsByTag(scenes, "Collectible");
// TODO: Write to file
Debug.Log(gameObjects.Count);
}
}