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
1
Question by aceofpack · Feb 04, 2016 at 06:18 AM · coroutinegridcoroutinessingleton

Using Grid-like singletons but have an issue with Coroutines.

Hi guys,

I followed @Fattie 's guidelines on the Grid.cs (Here) - but having an issue with a Coroutine.

In my game controller, I want to wait a small amount of time before Loading the level complete screen.

 //Small delay before level is complete
 StartCoroutine (LevelCompleteMinorDelay())

And the function...

 IEnumerator LevelCompleteMinorDelay()
 {
     yield return new WaitForSeconds(0.2f);
     SceneManager.LoadScene ("LevelComplete");
 }

The error I get is:

 MissingReferenceException: The object of type 'GameController' has been destroyed but you are still trying to access it.
 Your script should either check if it is null or you should not destroy the object.
 UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine)
 ...

This function is in a script which is attached to the __holder 'not destroyed' gameobject on preload, so I'm not sure why this happens. I prob don't understand enough about coroutines! Any help greatly appreciated :)

Comment
Add comment · Show 1
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 Fattie · Feb 04, 2016 at 11:53 AM 0
Share

Hey buddy .. what is Scene$$anonymous$$anager. ??

Note too that the error reads "The object of type 'GameController' has been destroyed" ... do you have a class called "GameController" ?!?

2 Replies

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

Answer by Fattie · Feb 04, 2016 at 11:51 AM

I want to wait a small amount of time before Loading the level complete screen.

You do that using

Invoke()

 Invoke( "LoadScene", 0.5f);

and then

   private void LoadScene()
     {
     .. your scene loading code ..
     }

It's important to NOT use coroutines for this. Use Invoke

Note - this would NOT be in your 'Grid.' static class.

Say you are loading your scene BestScene. This would simply be in a trivial script attached to any object in BestScene. It has nothing to do with "Grid". it's just a function you're running, in that scene - you see?

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 aceofpack · Feb 05, 2016 at 10:28 AM 0
Share

Cheers mate - I'll look to implement this. btw - Scenemanager is Unity 5.3's way of managing scenes. http://docs.unity3d.com/ScriptReference/Scene$$anonymous$$anagement.Scene$$anonymous$$anager.html

avatar image
0

Answer by aceofpack · Feb 04, 2016 at 07:17 AM

I managed to solve this with the following:

Creating an instance in that specific script at the top:

 public static GameController instance;

Assigning the instance to this in Awake();

 instance = this;

Calling coroutine like so:

 instance.StartCoroutine (LevelCompleteMinorDelay());
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 vijayrathore99 · Jun 08, 2017 at 03:13 PM 0
Share

Thanks a lot, solved the issue by this suggestion.

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

43 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

Related Questions

Why isn't my coroutine working when I call it from another script. 0 Answers

"Can't add script behaviour AICharacterControl. The script needs to derive from MonoBehaviour!" ? 0 Answers

Trouble with coroutine 0 Answers

How do I stop an automatically repeating Coroutine? 1 Answer

running a while loop until coroutine finishes 0 Answers


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