Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Derf321 · Apr 19, 2015 at 06:39 AM · coroutines

Coroutine couldn't be started because the the game object 'LevelManager' is inactive!

I'm getting this error when I'm trying to run a function from another script on the GameObject "LevelManager" (all javascript):

 saveScript.Load(saveScript.levelName);

From what I gather, the error usually occurs when you try and call a function on a GameObject that is disabled. However, I have no code for disabling, and when I run the following, it tells me the GameObject is active both before and after my function call.

 Debug.Log("Active?: " + GameObject.Find("LevelManager").active);
 saveScript.Load(saveScript.levelName);
 Debug.Log("Active?L " + GameObject.Find("LevelManager").active);

This function used to work fine a few days ago, I just noticed it stopped working, I don't know when or why. The weird part is I can call a test function on saveScript on the line before and it'll run fine.

Help is appreciated! =)

EDIT: Here's the saveScript (it's in Standard Assets):

 #pragma strict
 import System.Collections.Generic;
 import System.IO;
 import Parse;
 import System.Threading.Tasks;
 
 public static var filePath : String;
 public static var levelName = "$TEMP$";
 public static var receivedMessage;
 static var fakeball : GameObject;
 static var saveTask : Task;
 
 function Start () {
     if (Application.isEditor)
     filePath = Application.dataPath;
     else
     filePath = Application.persistentDataPath;
 }
 
 public function Save(upload : boolean) {
     Debug.Log("Saving");
     if (GameObject.Find("LevelName"))
         levelName = GameObject.Find("LevelName").GetComponent(UI.InputField).text;
     if (levelName == "" || levelName == null)
         GameObject.Find("ResultText").GetComponent(UI.Text).text = "Please Enter a Level Name";
     else
     {
         var gos = GameObject.FindGameObjectsWithTag("Pads") + GameObject.FindGameObjectsWithTag("Diamonds") + GameObject.FindGameObjectsWithTag("Wood") + GameObject.FindGameObjectsWithTag("Keys");
         var sPath : String = filePath + "/Levels/MyLevels/" + levelName + ".txt";
         var sData : StreamWriter = new StreamWriter(sPath);
         sData.WriteLine(levelName);
         for (var i = 0; i < gos.Length ; i++)
          {
                 sData.WriteLine(gos[i].name + "|" + gos[i].transform.position.ToString() + "|" + gos[i].transform.rotation.ToString() + "|");
            }
         sData.Flush();
         sData.Close();
         if (upload) {      
               var parseSave = Instantiate(Resources.Load("ParseSave"), Vector3(0,0,0), Quaternion.identity);
               parseSave.name = "ParseSave";
           }
     }
     Debug.Log("Saved!");
  }
   
  public function ParseLoad(level : String) {
       levelName = level;
       var parseLoad = Instantiate(Resources.Load("ParseLoad"), Vector3.zero, Quaternion.identity);
        parseLoad.name = "ParseLoad";
  }
  
  public function ReloadLevel() {
      Debug.Log("Reloading...");
      if (!(Application.loadedLevelName == "MainMenu"))
      {
         yield StartCoroutine(GameObject.Find("LevelManager").GetComponent(saveScript).Load (levelName));
         DestroyImmediate(GameObject.Find("Ball"));
         var ball = Instantiate(Resources.Load("Ball"), GameObject.Find("FakeBall").transform.position, Quaternion.identity);
         ball.name = "Ball";
         Destroy (GameObject.Find ("FakeBall"));
         ballScript.shotsTaken = 0;
         GameObject.Find("ParText").GetComponent(UI.Text).text = ballScript.shotsTaken.ToString();
     }
     else
         GameObject.Find("Ball").transform.position = Vector3(0,30,0);
  }
  
  public static function Load(level : String) {
      Debug.Log("LOADING");
      var gos = GameObject.FindGameObjectsWithTag("Pads") + GameObject.FindGameObjectsWithTag("Diamonds") + GameObject.FindGameObjectsWithTag("Wood") + GameObject.FindGameObjectsWithTag("Keys");
     for (var j = 0; j < gos.Length ; j++)
          Destroy(gos[j]);
      yield WaitForEndOfFrame();
      if (System.IO.File.Exists(filePath + "/Levels/Cache/" + level + ".txt"))
      {
          levelName = level;
         var lPath : String = filePath + "/Levels/Cache/" + level + ".txt";
         var lData : StreamReader = new StreamReader(lPath);
          var title = lData.ReadLine();
          for (var i = 0; !lData.EndOfStream ; i++)
          {
             var line = lData.ReadLine();
              var parsedLine = line.Split("|"[0]);
              var c = parsedLine[1].Substring(1,parsedLine[1].Length-2).Split(","[0]);
              var quat = parsedLine[2].Substring(1,parsedLine[2].Length-2).Split(","[0]);
              var item = Instantiate(Resources.Load(parsedLine[0]), Vector3(float.Parse(c[0].Trim()),float.Parse(c[1].Trim()),float.Parse(c[2].Trim())), Quaternion(float.Parse(quat[0].Trim()),float.Parse(quat[1].Trim()),float.Parse(quat[2].Trim()),float.Parse(quat[3].Trim())));
              item.name = parsedLine[0];
         }
         lData.Close();
     }
     
     globalScript.ResetVars();
     
     if (!GameObject.Find("FakeBall"))
     {
         fakeball = Instantiate(Resources.Load("FakeBall"), Vector3.zero, Quaternion.identity);
          fakeball.name = "FakeBall";
     }
     
     if (GameObject.Find("UserLevelsCanvas"))
         Destroy(GameObject.Find("UserLevelsCanvas"));
     
     Debug.Log("LOADED!");    
  }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Apr 19, 2015 at 07:54 AM 0
Share

You should paste the SaveScript class.

You could also put a debug in the Start of it to see if you would not have it on another object which happens to be inactive.

  void Start(){Debug.Log(name);}
avatar image Derf321 · Apr 20, 2015 at 02:32 PM 0
Share

Added, the saveScript is on a gameobject that is never destroyed (and kept between Application.Load's) so it should never be inactive

EDIT: Playing around with it, I found that it is Line 73 causing the problem, however I need it there in order for it to work properly. Is there an alternative way of writing it?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by lordlycastle · Apr 20, 2015 at 03:18 PM

The Load functions is static function, and aren’t you calling it with a instance? Either remove the static modifier or use the class name instead of instance. Also the return type of any function that contains yield should be IEnumerator.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Derf321 · Apr 21, 2015 at 04:03 AM 0
Share

I'll try and fix the static issue. I'm program$$anonymous$$g in javascript, I thought IEnumerator only exists (and is needed) in C#?

EDIT: I removed "Static" from the function (had to fix a few references to it too), and then made a function in the saveScript called Wait() that just had yield WaitForEndOfFrame(); and called that function ins$$anonymous$$d of directly using the yield inside the Load() function. It's a pretty roundabout way, the complexity of yield confuses me, but at least it's working perfectly! Cheers man!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to stop a single variant of a Coroutine? 1 Answer

Modify a boolean for all instances of a class 2 Answers

Brain exploding ... Problem with an internal Coroutine manager 3 Answers

Coroutines stop when another game goes fullscreen 1 Answer

I don't understand coroutines and invoke 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges