Search Unity

Help for this (Coroutine couldn't be started because the the game object is inactive!)

Discussion in 'Scripting' started by unity_1236alman, Mar 13, 2019.

  1. unity_1236alman

    unity_1236alman

    Joined:
    Mar 4, 2019
    Posts:
    66
    Code (CSharp):
    1. public void Start()
    2.     {
    3.         gameObject.SetActive(true);
    4.     }
    5.     public void StartToRotate()
    6.     {
    7.         StartCoroutine(Rotate());
    8.     }
    9.  
    10.     public IEnumerator Rotate()
    11.     {
    12.         while (true)
    13.         {
    14.             yield return new WaitForSeconds(1);
    15.             transform.Rotate(Vector3.one, RotationSpeed * Time.deltaTime, Space.World);
    16.         }
    17.     }
    Coroutine couldn't be started because the the game object 'BluCapsule' is inactive!
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    Goto:StartToRotate() (at Assets/Goto.cs:15)
    AuctionManager:Auction() (at Assets/AuctionManager.cs:76)
    <PausaAuctionPhase>d__22:MoveNext() (at Assets/AuctionManager.cs:52)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Well, the gameobject the script is on isn't active. So the coroutine can't start.
     
    Ryiah and Joe-Censored like this.
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Start() won't run unless the object is already active, so writing
    gameObject.SetActive(true);
    inside of Start() is useless.
     
    hopetolive, Ryiah and Joe-Censored like this.