Calling StartCoroutine() is not working

I have a Sphere prefab which is just a sphere with MoveSphere.cs script attached to it. It has Rotate() method which starts coroutine. The Rotate() method makes the sphere move along circle trajectory. The problem is when i call Rotate() method inside Start() method of MoveSphere.cs script it works fine, but when i try to call it inside Start() method of a GameController.cs script - it doesn’t work (the sphere stays at the same place). Here is my code for MoveSphere and GameController scripts:

public class MoveSphere : MonoBehaviour
{
    // ...some fields

    void Start()
    {
        rb = GetComponent<Rigidbody>();

        // if i uncomment next line of code - it works fine
        // Rotate();
    }

    public void Rotate()
    {
        StartCoroutine(rotate());
    }

    void Update() { }

    public IEnumerator rotate()
    {
        int n = (int)(360 / dAngle);
        float da = 360f / n;
        vAmp = radius * da * Mathf.Deg2Rad / dt;
        currentAngle = 0;
        for (int i = 0; i < n; i++)
        {
            Vector3 pos = getPosition(currentAngle);
            currentAngle += da;
            rb.position = pos;
            yield return new WaitForSeconds(dt);
        }
    }

    //...some mathematical methods
}

public class GameController : MonoBehaviour
{
    public GameObject obj;
    public int numOfInstances;

    // Use this for initialization
    void Start ()
    {
        GameObject sphere1 = Instantiate(obj, new Vector3(-5,0,-2), Quaternion.identity);

        // this one doesn't work
        sphere1.GetComponent<MoveSphere>().Rotate();
    }

    void Update () { }
}

Is “sphere1” assigned to the sphere gameobject? If so, does the getcomponent part actually get the component? To find out, instead use “MoveSphere mS = sphere1.GetComponent…();” and then on the next line check if it found it with “Debug.Log(mS);” and if it comes up null, it didn’t find it properly, and something isn’t right in the connection to sphere1.

Note: due to the formatting of answers, the MoveSphere part of getcomponent is being edited out of my answer :smiley: - but you get what I mean I figure :stuck_out_tongue:

put StartCoroutine(rotate()); inside Start() function. I hope this would work.