SceneManager doesn't get Scene by name

I have 3 scenes in my Unity project and trying to get a scene index by its name. I’m trying to use SceneManager but I can’t figure out how to use SceneManager.GetSceneByName . Using

SceneManager.GetSceneByName("Scene1");

returns null while I can load the scene using

SceneManager.LoadScene("Scene1",LoadSceneMode.Single);

Also SceneManager.sceneCount returns 1 while I have 3 scenes.

Unity documents for GetSceneByName says:

Searches through the scenes added to the SceneManager for a scene with the given name.

The name has to be without the .unity extension. The name can be the
last part of the name as displayed in the BuildSettings window in
which case the first scene that matches will be returned. The name
could also the be path as displayed in the Build Settings, still
without the extension, in which case only the exact match will be
returned. This is case insensitive.

Does it mean I should add all the scenes to the SceneManager first?

How can I do that?

If so, then why SceneManager.LoadScene() works with the scene name without adding it to the SceneManager?

Note: I’ve already added all 3 scenes to the Build setting.

I might be wrong, but I think GetSceneByName and sceneCount both work over the loaded scenes, not the scenes of the project. If you load a scene using additive mode then sceneCount will return 2 and GetSceneByName will be able to find any of those 2 scenes.

SceneManager.GetSceneByName returns a Scene object, not index. To access the index of the scene you have to use the buildIndex field.

SceneManager.GetSceneByName("Scene1").buildIndex;

Also, make sure that all of your scenes are included in the build (FileBuild SettingsScenes in Build).