Error in MusicPlayer.cs

facing an error while
int numMusicPlayers = FindObjectsOfType().Length;

From the help from (Ctrl+ .) it is saying to add a line [System.Obselete] to fix this error but i want to know what is this error and why i am facing it and why should i add [System.Obselete] in my code before error?

Hi @TR_GameDeveloper,

Which version of Unity do you use? And have you already hovered your mouse over the concerning line?

In newer version of Unity, it might be that the method is replaced (see the API). The warning message should tell you what the new method name is you are supposed to use. Rename FindObjectsOfType accordingly, then the code should work as expected.


See also:

getting this while hovering

The relevant part is this:

image

Have you tried to rename your FindObjectsOfType method to FindObjectsByType?

Having this now

Try to add
image

between the parentheses ().

As we can see in the API, there is no version without any parameter or with a default value. For this reason, we have to pass on a value.

If the generic method did not work, you could apply the example from the API:

FindObjectsByType(typeof(MusicPlayer), FindObjectsSortMode.None);

Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms