How can I create an empty GameObject in each project scene via editor script?

I’m trying to create the GUI button which iterates through each project scene and creates a new GameObject instance in it. However, no gameobject appears in any scene.
I have the following method being called when the button is pressed.

private void GenerateDatabaseForEachScene()
{
	EditorBuildSettingsScene[] allScenes = EditorBuildSettings.scenes;
	foreach (EditorBuildSettingsScene scene in allScenes)
	{
		EditorSceneManager.OpenScene(scene.scenePath, OpenSceneMode.Single);
		GameObject emptyDatabase = CreateEmptyDatabaseForCurrentScene(scene.scenePath);
	}
}

And I use static method CreateEmptyDatabaseForCurrentScene() to create an empty gameobject:

private static GameObject CreateEmptyDatabaseForCurrentScene()
{
	Scene currentScene = EditorSceneManager.GetActiveScene();
	if (!currentScene.IsValid())
	{
		Debug.LogErrorFormat("A database can be created only if any scene is opened.");
		return null;
	}
	
	GameObject databaseObject = new GameObject("Database - " + currentScene.name);
	databaseObject.SetActive(true);
	databaseObject.hideFlags = HideFlags.None;
	Debug.Log("The scene of the gameobject created: " + databaseObject.scene.path);
	return databaseObject;
}

As you can see, I’m writing the scene where the new gameobject were placed in console. And the correct scene is shown:

59934-edfghn.png

But the gameobject doesn’t appear in the scene! Moreover, the method Object.FindObjectsOfType(typeof(GameObject)) returns the array of all objects present in the current scene, but the new gameobject is absent there.

Please, can anybody explain what I’m doing wrong?

I’ve found the reason of my problem. A new gameobject doesn’t appear in the scene because it isn’t saved before opening the next scene. So, in order for changes to take place the method iterating over scenes must be rewritten as follows:

private void GenerateDatabaseForEachScene()
{
	EditorBuildSettingsScene[] allScenes = EditorBuildSettings.scenes;
	foreach (EditorBuildSettingsScene scene in allScenes)
	{
		Scene sceneRef = EditorSceneManager.OpenScene(scene.scenePath, OpenSceneMode.Single);
		GameObject emptyDatabase = CreateEmptyDatabaseForCurrentScene(scene.scenePath);
		EditorSceneManager.SaveScene(sceneRef);
	}
}

Now everything works correctly. A new gameobject appears in each scene as it was expected to.

when I want to create a new object in different scenes I use this code:

GameObject Object= Object.Find("ObjectName");
        if (Object== null)
        {
            Object= new GameObject("ObjectName"); // If the scirpt cannot find the GameData object then create a new one
        }