how to correct the deprecated FindObjectsOfType??

Hello, i have this script that works perfectly with the deprecated FindObjectsOfType<>(); I am in Unity 2023.1

using System.Collections.Generic;
using UnityEngine;



public class ManagerNiveau : MonoBehaviour
{
   public static ManagerNiveau instance;
   private void Awake()
   {
       instance = this; 
   }
   public bool niveauActif;
   private VieChateau cechateau;
   public List <VieEnnemi> ennemisactifs=new List<VieEnnemi>();
   private VaguesEnnemis [] mesVagues; // nouvelle variable qui va regarder nos vagues d'ennemis
   void Start()
   {
       cechateau=FindFirstObjectByType<VieChateau>();
       niveauActif = true;
       ManagerSons.instance.JoueBGmusique();
       mesVagues= FindObjectsOfType<VaguesEnnemis>(); // associe aux bons objets avec les bons scripts
   }
   void Update()
   {
       if(niveauActif)
       {
           if(cechateau.vieActuelle <=0)
           {
               niveauActif = false;
               UIController.instance.ecranperdant.SetActive(true);



           }



           bool vaguesCompletes = true; // un booléen qui détecte si nos vagues sont complétées
           foreach(VaguesEnnemis monspawn in mesVagues) //pour chaque spawner
           {
               if(monspawn.vaguesacreer.Count > 0) // tant qu'il y a des vagues Ă  venir
               {
                   vaguesCompletes = false; // nos vagues ne sont pas complétées
               }
           }





           if(ennemisactifs.Count ==0 &&vaguesCompletes) // on ajoute le fait que les vagues sont complétées
           {
               niveauActif = false;
               UIController.instance.ecrangagnant.SetActive(true);
           }
       }
   }
}

On line 22, when i try to convert mesVagues= FindObjectsOfType();

BY

mesVagues= FindObjectsByType(); i have error C1501, it needs another parameter in the parenthesis but i have no idea what to put there. The documentation makes me a little confuse there.

Anyone who knows what i must put in the parameter? It worked perfectly with FindFirstObjectByType but not with FindObjectsByType. Why?

Thanks for your help

1 Like

https://docs.unity3d.com/ScriptReference/Object.FindObjectsByType.html
It even has example code in the manual…

A sort mode as is mentioned in the documentation.

https://docs.unity3d.com/ScriptReference/FindObjectsSortMode.html

Alternatively learn to write code that doesn’t depend on the crutch that is the Find methods.

thanks a lot!! I didn’t knew it was a none parameter, i was searching for a parameter inside the script class called.

It worked!!! :slight_smile:

4 Likes

Use the right tool for the job => this should be a popup message when signing up to the forum with an “I Agree” button. :slight_smile: