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 devFd · Sep 07, 2017 at 06:31 AM · gameobjectobjectnot workingpooling

gameObject.SetActive(false); not working as intended

So I am trying to make my coins disappear.

PickUpPoints.cs

 IEnumerator waitOneSecond(GameObject targetDisable)
     {
         yield return new WaitForSeconds (1f); //wait 1 second
         targetDisable.SetActive (false); //disables coin particles
         theTimeCounter.DestroyCoin (); //destroy coin (event in another script)
     }

TimeCounter.cs

 public class TimeCounter : MonoBehaviour {
     public void DestroyCoin () {
         gameObject.SetActive (false);
         Debug.Log ("destroyd");
     }
 }
 

The Debug.Log message is shown which means it 'works' but gameObject is still shown.

Both of the scripts belong to a prefab coin (as shown in the badly cropped image below) alt text

Any solutions to why it won't disappear and how to make it disappear itself? ~Thanks

accurate.png (32.4 kB)
Comment
Add comment · Show 2
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 $$anonymous$$ · Sep 07, 2017 at 06:41 AM 0
Share

How are you getting the theTimeCounter reference?

avatar image devFd $$anonymous$$ · Sep 07, 2017 at 06:48 AM 0
Share

Inside PickUpPoints.cs

 public TimeCounter theTimeCounter;
     
 theTimeCounter = GetComponent<TimeCounter>();


idk if its correct or not so @$$anonymous$$

3 Replies

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

Answer by game4444 · Sep 07, 2017 at 07:25 AM

Is there another script enabling coin? Please checkout. Your code looks fine. It should disable gameObject.

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 devFd · Sep 07, 2017 at 07:45 AM 0
Share

Turns out there was a GroundDestroyer script attached to it which was supposed to make the coins which weren't collected dissapear but it shouldn't interfere with this.

GroundDestroyer.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GroundDestroyer : $$anonymous$$onoBehaviour {
 
     public GameObject groundDestructionPoint;
 
     // Use this for initialization
     void Start () {
         groundDestructionPoint = GameObject.Find ("GroundDestructionPoint");
     }
     
     // Update is called once per frame
     void Update () {
 
         if (transform.position.x < groundDestructionPoint.transform.position.x) 
         {
 
             //Destroy (gameObject);    
 
             gameObject.SetActive (false);
 
         }
     }
 }
 
avatar image devFd · Sep 07, 2017 at 07:54 AM 0
Share

after a few tweaking it works. :)

avatar image EclecticSteve · Jul 20, 2018 at 06:52 PM 0
Share

I had the same problem - of course there was another script enabling the thing which I had such bad luck getting to go away.

Thank you for your comment - after reading it I went back through, found the offending script, and tweaked it successfully.

avatar image
0

Answer by markusarilius · Sep 07, 2017 at 07:10 AM

I may be wrong but I don't see anything passed to the destroy coin function. It may have been passed some other way but unless it has what is it destroying if it hasn't been passed something?

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 devFd · Sep 07, 2017 at 07:20 AM 0
Share

What do you mean? I can't understand your question but I'm gonna try to elaborate how I think this works.

In PickUpPoints.cs

  theTimeCounter.DestroyCoin ();

triggers

In TimeCounter.cs

 public void DestroyCoin () {
          gameObject.SetActive (false);
          Debug.Log ("destroyd");
 

If I'm not wrong, gameObject (lower case g) means the object the script is attached to (correct me if I'm wrong .-.) so technically this should work?

but it doesn't sooo (

avatar image
0

Answer by Purplepigfarm · Sep 08, 2017 at 08:48 PM

I have the same problem. Trying to disable a gameobject with gameObject.SetActive(false); but to no avail. Not accessing it from any other script either.

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 Must_I_have_a_name · Sep 08, 2017 at 09:39 PM 0
Share

I am having a similar problem but the problem is to get a non-active child gameobject TO appear, not to disappear. I mention this because I wonder if the problem might be more precisely stated that .SetActive() sometimes isn't working as expected.

$$anonymous$$y question was "Is there a specific technique you have to use to .SetActive() a child GameObject of a GameObject you created using Resources.Load?", so you can look at what I said about the problem. I asked the question a little earlier today.

Are you calling .SetActive(false) inside a method in a class that is $$anonymous$$onobehavior? I have noticed that some Unity commands must be made in that class and won't work if you jump outside $$anonymous$$onobehavior to some other C# class that does NOT inherit from $$anonymous$$onobehavior and try to do the command there. Instantiate(Resources.Load()) and Destroy() are an examples of commands that will fail if you do it outside $$anonymous$$onobehavior. Unless I am somehow wrong about that.

Did you create your coins using instantiate(Resources.Load())? If there were and you created them outside a $$anonymous$$onobehavior class then maybe you could try jumping to inside a method of some $$anonymous$$onobehavior based class and create your coins there (THEN try to disappear them).

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

103 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

Related Questions

Pooling GameObjects with TextMesh ? 0 Answers

Can't Return the Tag of a Child Object 4 Answers

Removing objects from an array 2 Answers

How to remove objects from a list ? 3 Answers

object not spawning but no error message 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