Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug how to correct the deprecated FindObjectsOfType??

Discussion in 'Scripting' started by westergard, May 17, 2024.

  1. westergard

    westergard

    Joined:
    May 4, 2015
    Posts:
    101
    Hello, i have this script that works perfectly with the deprecated FindObjectsOfType<>(); I am in Unity 2023.1

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4.  
    5.  
    6. public class ManagerNiveau : MonoBehaviour
    7. {
    8.    public static ManagerNiveau instance;
    9.    private void Awake()
    10.    {
    11.        instance = this;
    12.    }
    13.    public bool niveauActif;
    14.    private VieChateau cechateau;
    15.    public List <VieEnnemi> ennemisactifs=new List<VieEnnemi>();
    16.    private VaguesEnnemis [] mesVagues; // nouvelle variable qui va regarder nos vagues d'ennemis
    17.    void Start()
    18.    {
    19.        cechateau=FindFirstObjectByType<VieChateau>();
    20.        niveauActif = true;
    21.        ManagerSons.instance.JoueBGmusique();
    22.        mesVagues= FindObjectsOfType<VaguesEnnemis>(); // associe aux bons objets avec les bons scripts
    23.    }
    24.    void Update()
    25.    {
    26.        if(niveauActif)
    27.        {
    28.            if(cechateau.vieActuelle <=0)
    29.            {
    30.                niveauActif = false;
    31.                UIController.instance.ecranperdant.SetActive(true);
    32.  
    33.  
    34.  
    35.            }
    36.  
    37.  
    38.  
    39.            bool vaguesCompletes = true; // un booléen qui détecte si nos vagues sont complétées
    40.            foreach(VaguesEnnemis monspawn in mesVagues) //pour chaque spawner
    41.            {
    42.                if(monspawn.vaguesacreer.Count > 0) // tant qu'il y a des vagues à venir
    43.                {
    44.                    vaguesCompletes = false; // nos vagues ne sont pas complétées
    45.                }
    46.            }
    47.  
    48.  
    49.  
    50.  
    51.  
    52.            if(ennemisactifs.Count ==0 &&vaguesCompletes) // on ajoute le fait que les vagues sont complétées
    53.            {
    54.                niveauActif = false;
    55.                UIController.instance.ecrangagnant.SetActive(true);
    56.            }
    57.        }
    58.    }
    59. }
    60.  
    On line 22, when i try to convert mesVagues= FindObjectsOfType<VaguesEnnemis>();

    BY

    mesVagues= FindObjectsByType<VaguesEnnemis>(); 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
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 5, 2024
    Posts:
    552
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,690
  4. westergard

    westergard

    Joined:
    May 4, 2015
    Posts:
    101
    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!!! :)
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,559
    tier-list.png
     
    Lekret, CodeSmile and Ryiah like this.
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,934
    Use the right tool for the job => this should be a popup message when signing up to the forum with an "I Agree" button. :)