"not all code paths return a value"

hi!

Beginner here. I need this method to return a GameObject based on it’s id (which is an enum named “ItemID”), and I don’t know where I’m missing a return value.
“pickUpDict” is the dictionary from which to retrieve the GameObject, which is located in the same script and populated on Awake.

Hope someone can help me out. Thanx in advance!

public static Dictionary <GameObject, ItemID> pickUpDict = new Dictionary <GameObject, ItemID>(); //container for all pickups

//return gameobject based on item id, from dictionary
public static GameObject ReturnPrefab (ItemID id) {
    		GameObject go = null;
    		foreach (var kvp in pickUpDict) {
    			if (kvp.Value == id) {
    				go = kvp.Key;
    				return go;
    			} 
    			else
    				return null;
    		}
    	}

That code doesn’t make much sense as it will only check the very first item in the dictionary.

Isn’t this what you want?

public static GameObject ReturnPrefab (ItemID id)
{
  foreach (var kvp in pickUpDict)
  {
    if (kvp.Value == id)
      return kvp.Key;
  }
  return null;
}