Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Gng357 · Nov 23, 2018 at 02:59 PM · scenescoroutinesscene change

Coroutine couldn't be started because the game object 'Scene Loader' is inactive

I have a main scene with 2 buttons, where each button should open other scene (button 1 => scene 1, button 2 = > scene 2) and in each of these scenes I have a back button that should go back to the main scene.

I manage to do that successfully but when I use a Coroutine so I can have a delay of 2 seconds while loading the next scene, I get the following error when I click "Back to main scene" button:

Coroutine couldn't be started because the the game object 'Scene Loader' is inactive! Here is my code:

 > public class SceneLoader :
 > MonoBehaviour {
 > 
 >     public void LoadNextScene(int numberOfScene)
 >     {  
 >         StartCoroutine(LoadAfterSeconds(numberOfScene));
 > 
 >     }
 > 
 >     private IEnumerator LoadAfterSeconds(int numberOfScene)
 >     {
 >             yield return new WaitForSeconds(2f);
 > 
 >             SceneManager.LoadScene(numberOfScene);
 >     }
 > 
 > }

When I am in the main screen and I click on the button 1 or 2 to go to the other scenes it's working as intended after 2 seconds, but when I click "Back to main scene" it doesn't do anything and I get the error that the game object 'Scene Loader' is inactive!

I know I could use Invoke() but I would like to understand what I am doing wrong.

Any help is appreciated.

Thank you.

Comment
Add comment · Show 5
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 Bonfire-Boy · Nov 23, 2018 at 04:47 PM 0
Share

If you're saying that you don't understand how it's come to be inactive, I would suggest adding an OnDisable function with logging. That should shed some light on how/when it's being turned off.

avatar image PizzaPie · Nov 23, 2018 at 05:56 PM 0
Share

Odds are, in the second scene you have the instance of this class disabled. Also what is the point of the loop? In any case it will run once completly and the second time till the first yield statment, after that the scene will get destroyed thus the coroutine will stop.

avatar image Gng357 PizzaPie · Nov 26, 2018 at 10:38 AM 0
Share

Thank you for your reply @PizzaPie Indeed I know that loop "while(check)" is not used at all, it was there when I was trying something and I accidentally forgot to remove it. How can I keep it persist so the scene won't get destroyed (and coroutine won't stop) and being able to move between scenes?

avatar image PizzaPie Gng357 · Nov 26, 2018 at 01:07 PM 1
Share

It doesn't make sence to make the object persistent, it will perplex things, and you don't need it.

You need a GameObject in each Scene with the SceneLoader component on it. Then assign in each button's onClick Event in the Object field the GameObject with SceneLoader script (make sure you find it in the Scene tab of the Object assigner or drag and drop the GameObject that resides in active Scene) and assign the other two fields. $$anonymous$$ake sure the GameObject with LoadScene script is active in all scenes.

Show more comments

1 Reply

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

Answer by PizzaPie · Nov 26, 2018 at 03:24 PM

Probably you assign the prefab(asset) in onClick event and not the active instance of it you should have in the scene.

I suggest visiting Learn section and go through, at least, the basic tutorials, before trying moving further.

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 Gng357 · Nov 26, 2018 at 03:37 PM 0
Share

Yep, that was the problem. Thank you PizzaPie! Write this as answer so I can upvote it :) Να'σε καλα!!

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

98 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I have multiple scenes at once, updating, but sanboxed from eachother? 0 Answers

I have several scenes in 3D, and I want them to change after colliding the player with an object. How do I do this? 1 Answer

How to passing levels automatically in games? 0 Answers

Working with multiple scenes? 0 Answers

Problem with script in multiple scenes needing to refer to FPS Controller. 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