How do I find all objects that have the same script using 'Find'?

I need to find all objects that have the ‘Stage’ script.

Below is the code:

public void stageSelectButton() {
var stageList = FindObjectsOfType<Stage>(); //Get all objects with the 'Stage' script in this Scene.

foreach (var stage in stageList) {
if (stage.stageSelected) { //Check if it is the selected stage
stage.OpenStage(); //Open the stage, if it is available
}
}
}

The problem is that ‘FindObjectsOfType’ is obsolete, asking to change it to ‘FindFirstObjectByType’, and I’m getting an error:

Assets\scripts\controllers\GCStageSelect.cs(17,28): warning CS0618: ‘Object.FindObjectsOfType()’ is obsolete: ‘Object.FindObjectsOfType has been deprecated. Use Object.FindObjectsByType instead which lets you decide whether you need the results sorted or not. FindObjectsOfType sorts the results by InstanceID but if you do not need this using FindObjectSortMode.None is considerably faster.’

How do I get all objects that have the ‘Stage’ script with the stageList variable?

I could define all these objects with the tag ‘Stage’, for example, and use 'GameObject.FindGameObjectsWithTag(“Stage”) to get them, but to not define tags and directly search for the objects that have the script ‘Stage’, how do I write it correctly?

Thats why they made findobjects(<-)oftype

note the s, returns all of a type

Yes, but FindObjectsOfType is obsolet. Before it worked by returning all the ‘Stage’ objects to me in a variable.
Now, I want to use another method to get all objects that have the same component, and not the same tag like GameObject.FindGameObjectsWithTag’ does.

According to the FindObjectsOfType documentation, you should be using FindObjectsByType instead. Here is the documentation for the latter/newer method:

The page linked above contains a code example showing how to use it. It looks quite similar to the obsolete FindObjectsOfType method, except that it allows you to choose whether the resulting array is sorted (by Instance ID) or unsorted.

Ok, now I get it, I must add ‘FindObjectsSortMode.None’ for it to work.
Thank you friend!