Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by TheBigE · Dec 31, 2012 at 07:58 AM · coroutine

When OnBecameInvisible been called

Hi All,

I have this weird thing goining on. I use OnBecameInvisible when my character is no longer seen by the main camera. When it is not visible bu the main camera I start a coroutine:

 void OnBecameInvisible()
     {
 
         someComponent.enabled = false;
         StartCoroutine(SomeCoroutine());
 
     }

It works great utill I stop running the game in the editor (when I press the play button again to stop running the game) and I get this console error :

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

UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) guy is the name of my character where the script is attcahed. Any ideas? Thank u in advance
Comment
Add comment
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

2 Replies

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

Answer by magavelis · Apr 10, 2013 at 03:40 AM

Probably an answer is too late, but today i spent some time with the same issue and find out a solution by using this method:

void OnApplicationQuit() {
    activated = false;
}

need to add if statement in your OnBecameInvisible() method, like this:

void OnBecameInvisible() {

 if(activated == true) {
     // your code
 }

}

don't forget to initialize "bool activated = true;" variable at beginning of the script.

Comment
Add comment · Show 2 · 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 JesterGameCraft · Dec 29, 2021 at 09:17 PM 0
Share

Although I don't like the fact that OnBecomeInvisible get's called by default when application quits, it does kind of make sense. In any case I've used your workaround to get rid of the pesky error message at each editor quit. Thanks.

avatar image KarlKarl2000 · Mar 13 at 07:10 AM 0
Share

I was going nuts trying to figure out what it was ...

I tried OnDisable() and OnDestroy() ... but didn't know about OnApplicationQuit()

Thanks for this

avatar image
1

Answer by Maulik2208 · Dec 31, 2012 at 08:46 AM

you have Disabled the Guy by script but you didn't enabled it after Coroutine so ... SomeComponent.enabled = false; StartCoroutine(SomeCoroutine()); someComponent.enabled = true;

And Enjoy....Cheers.....Don't forget to mark the answer if helped you.....

Comment
Add comment · Show 7 · 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 TheBigE · Dec 31, 2012 at 10:09 AM 0
Share

Thank u for your answer but I don't disable Guy (name of game object) only one component of it. $$anonymous$$oreover I enable the component at the end of the coroutine..

avatar image Maulik2208 · Dec 31, 2012 at 10:27 AM 0
Share

Then whats the issue you are facing now?

avatar image TheBigE · Dec 31, 2012 at 10:50 AM 0
Share

The console error above when i stop running the game in the editor

avatar image Maulik2208 · Dec 31, 2012 at 11:12 AM 0
Share

try Guy.active = true; in Start function

avatar image TheBigE · Dec 31, 2012 at 11:45 AM 0
Share

Guy is active at the beginning of the game. its active all the time that why I don't understand the console error at the end of the game (when I press play the second time to stop the game in the editor)

Show more comments

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

12 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

Related Questions

Coroutine exiting unexpected 1 Answer

Issue With Rotation on Key Press 1 Answer

Instantiate at Intervals 2 Answers

Shooting bullets OnMouseDrag, time delay issues 3 Answers

A loop FOR waits for a coroutine to end 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