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 zacharif · Dec 22, 2019 at 04:20 AM · 3dswitchclonefalseoff

Disabled script still runs.

Yes, I know this is a duplicate but I am very confused. I disable a cloning script kindly attained by the nice people who answer here and if I switch it off it still runs, here it is.

using System.Collections; using System.Collections.Generic; using UnityEngine; public class clonefor4 : MonoBehaviour { public GameObject MyObjectToClone; Vector3 offset = new Vector3(2, 0, 2); // Start is called before the first frame update void Start() { StartCoroutine("Spawner"); } IEnumerator Spawner() { while (true) { GameObject clone = Instantiate(MyObjectToClone, transform.position + offset, Quaternion.identity); clone.transform.position = new Vector3(clone.transform.position.x, 8f, clone.transform.position.z); clone.transform.position = transform.position + offset; clone.transform.position = new Vector3(clone.transform.position.x, 4f, clone.transform.position.z); yield return new WaitForSeconds(10); } } } but if I disable it FindObjectOfType<clonefor4>().enabled = false; It still functions, is there any way to completely shut off the script? I know if (!enabled) return; has something to do with it. Any ideas? Thanks!

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

1 Reply

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

Answer by IINovaII · Dec 22, 2019 at 07:25 AM

The reason why the coroutine still runs is because you are only deactivating the script. Coroutine will still run even if the script is disabled as long as the gameobject it is attached to is enabled. In order to completely stop the coroutine, you can try one of the following methods.

  • Stop the coroutine using StopCoroutine or StopAllCoroutines functions

  • Disable the gameobject which the script is attached to instead of just disabling the script.

Comment
Add comment · Show 3 · 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 zacharif · Dec 22, 2019 at 05:17 PM 0
Share

Thanks, this seems to work!

avatar image IINovaII zacharif · Dec 22, 2019 at 05:23 PM 0
Share

Anytime! You can mark it as answer then.

avatar image reikovaaa · Jul 13, 2020 at 08:30 PM 0
Share

I was working on a door function with two scripts. One for the door, and another for a broken door. Silly me didn't know that scripts still work when disabled and that is a hard lesson learned. People, don't be the guy wondering why your scripts suddenly stop working, don't spend 7 hours like me :]

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

153 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 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 clone randomly 2 0 Answers

How to stop all StopAllCoroutines(); from another script 1 Answer

How to clone with a object. 3 Answers

Switch between two light sources 3 Answers

Cloning a game object. 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