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 /
avatar image
0
Question by NoodleCup · Jun 29, 2019 at 02:49 AM · gamequitpersistenceonbecameinvisible

How do i stop OnBecameInvisible being used when I exit game?

Noob question, but I've been googling for the past 2 hours with no avail.

Im getting rid of objects by using OnBecameInvisible, and using this to call on a function that will replace the objects that have been deleted to the front of the stack.

When I exit the game, I get a bunch of created objects as if the player ran past them with this error

Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)

I tracked the issue down to the OnBecameInvisible function.. how can would I stop this being ran when I exit the game so that I don't get a bunch of random clones in my editor scene.

this is a endless runner type of game, I don't think It would effect the game but running the game to test it constantly creates these objects I have to delete manually.

Should I just stop using the OnBecameInvisible function all together? and go to a system that uses colliders with OnCollisionExit? or am I able to remedy this situation somehow?

Thanks in advance fellas.

scripts

 public class Platform : MonoBehaviour
 {
     private InfinitePlanes infinitePlanes;
 
     private void OnEnable()
     {
         infinitePlanes = GameObject.FindObjectOfType<InfinitePlanes>();
     }
 
     public void OnBecameInvisible()
     {
         infinitePlanes.RecyclePlatform();
         //this.gameObject.SetActive(false);
         
     }
 }



TLDR the RecyclePlatform creates more platforms at the front of the terrain stack. once I exit game, it creates a bunch of clones I have to delete at the front of the stack. how to stop it from doing its job when I quit the game? as that's going above and beyond its needs.

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 NoodleCup · Jun 29, 2019 at 02:50 AM 0
Share

Ill be honest, 2 hours is me downplaying my incompetence, I've spent my whole day off trying to resolve this weird issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by NoodleCup · Jun 29, 2019 at 03:27 AM

I feel like once I post a question on the forums, I go into overdrive to figure out the problem I'm having.

this example from a completely different situation has helped me solve this issue.

 bool quitting;
 
  void OnApplicationQuit() {
      quitting = true;
  }
 
  void OnDestroy() {
      if (quitting) {
          //application is quitting; don't spawn more stuff
      } else {
          //application is running, proceed normally
      }
  }

Comment
Add comment · 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

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

142 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 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

Quit application before relaunching to specific scene 1 Answer

getting udp package info inside unity (GlovePIE) 0 Answers

quiting the game when triggered 1 Answer

Quit button 1 Answer

End/Pause Game! 2 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