Fading in a GameObject using IEnumerator

I am trying to Instantiate a enemy prefab at random intervals. The enemy should fade in gradually instead of just appearing.

This is what I have so far:

using UnityEngine;
using System.Collections;

public class SpawnEnemy : MonoBehaviour
{
    public GameObject prefab;
    public GameObject[] spawnPoints;
    public float minTime = 5.0f;
    public float maxTime = 10.0f;
    public float fadeInDuration = 3.0f;

    // Use this for initialization
    void Start()
    {
        Invoke("Spawn", Random.Range(minTime, maxTime));
    }

    void Spawn()
    {
        GameObject instance = (GameObject)Instantiate(prefab, spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position, Quaternion.identity);
        StartCoroutine(FadeIn(instance.GetComponentInChildren<SkinnedMeshRenderer>().material.color)); 

        Invoke("Spawn", Random.Range(minTime, maxTime));
    }

    IEnumerator FadeIn(Color instanceColor) {
        for (float t = 0.0f; t < fadeInDuration; t += Time.deltaTime)
        {
            instanceColor = Color.Lerp(new Color(1.0f, 1.0f, 1.0f, 0.0f), new Color(1.0f, 1.0f, 1.0f, 1.0f), t / fadeInDuration);
            yield return instanceColor;
        }
    }

}

However, the enemy just appears instantly as the spawn point with no noticable fade in. What I am doing wrong? I feel like I’m missing something obvious, but all I could find for answers relating to this question used the Update() function.

Colors are passed by value instead of reference. Your StartCoroutine is just sending a copy of the color values, so the coroutine is working on it’s own copy. Also, coroutines don’t return any value to the calling code since they are run over multiple frames. There’s no way for the calling line from a normal method to get a value back. The yield command controls the timing of the coroutine.

You’ll need to send either the Renderer or it’s Material to the coroutine to work on, since those are passed by reference.

void Spawn()
{
     //stuff
     StartCoroutine(FadeIn(instance.GetComponentInChildren<SkinnedMeshRenderer>().material));
}

IEnumerator FadeIn(Material mat)
{
     for()
     {
          //Adjust mat.color here
          yield return null; //Wait one frame
     }
}