generic FindObjectsOfType still bugged?

how would i get this to work…

private List<Food> food= new List<Food>();
Food[] foods=FindObjectsOfType(typeof(Food))as Food[];
foreach(Food f in foods) 
		{
			food.Add(f);
		}

error: Cannot convert type UnityEngine.Object[ ]' to Food[ ]’ via a built-in conversion

my goal is to get a list with all the food instances in the scene and then run

public int FindFood ()
	{
		//go to nearest food
		for(int i=0; i<_food.Count; i++)
		{
			int index=0;
			float dist= Vector3.Distance(_food[0].Position, _position);
			float closest= Vector3.Distance(_food[i].Position, _position);
			if(closest < dist)
			{	
				index = _food[i];
				dist = closest;
			}
		}
		return index;
	}

What are you using as the base class of Food?
For the conversion to work it would need to be something that’s derived from UnityEngine.Object (eg. MonoBehaviour, ScriptableObject).

ah k i derived from nothing asuming it then direves fromObject. so UnityEngine.Object is different? I’ll try ScriptableObject.

Yes, deriving from nothing means your class is the base/parent/first ancestor class.

so it is deriving from Object then? so whats the difference between UnityEngine.Object and Object (where all is derived from in C#)?

If you don’t specify a base class then it will use System.Object. This is not the same as UnityEngine.Object. UnityEngine.Object is derived from System.Object though.

FindObjectsOfType will only consider things derived from UnityEngine.Object. This kind of makes sense because you wouldn’t want to to search though all the thousands of objects derived from System.Object (eg. strings).