• 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
Question by Skuzzbag · Jun 27, 2011 at 03:53 PM · gameobjectactive

gameObject.active still draws object

How can I stop them getting drawn? I've created a number of particle objects and setting active to false has stopped them updating but they still get drawn on the screen.

Comment

People who like this

0 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 rocket5tim · Jun 27, 2011 at 04:17 PM 0
Share

Can you post your code? gameObject.active = false will disable the game object including the rendering node. Are you setting renderer.enabled = true by any chance? Although even that wouldn't work if you're disabling the gameobject properly. Does it still render if you uncheck the checkbox in the top left corner of the inspector (while your object is selected in Unity)?

avatar image Chris D · Jun 27, 2011 at 05:20 PM 0
Share

@Skuzzbag - please don't post comments as answers. Instead, post clarifications as comments or edits on your original post (until you gain the ability to comment on other users' answers). Keeping the answer area tidy helps people see what's going on and where the dialogue currently stands.

3 Replies

· Add your reply
  • Sort: 
avatar image

Answer by DavidDebnar · Jun 27, 2011 at 04:41 PM

If its a particle effect, everything you need to do is something like this:

function Update () { gameObject.particleEmitter.emit = false; }

Comment

People who like this

0 Show 0 · 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

Answer by Skuzzbag · Jun 27, 2011 at 05:02 PM

It's not a Unity particle emitter (I'm hoping I'm not confusing the issue by naming it so) as I wanted to use some primitive shapes for the particles.

The codes a bit long text wise because of my long variable names!

There are 3 instantiate lines in the loop as I'm creating and storing the reference to 3 different particle objects.

The objects are drawing at the default location 0,0,0 even though they are active = false

function Start () { shipControlScript = playerShip.GetComponent("ShipControl_script"); // reference to ship control script

 explosionEventScript = explosionEvent.GetComponent("ExplosionEvent_script");
 
 particleArray = new GameObject[shipControlScript.maxMissiles * explosionEventScript.numberOfParticles];

 print("Array size = " + shipControlScript.maxMissiles * explosionEventScript.numberOfParticles);
 
 // Setup the array with the pre-cooked prefabs - they are deactivated.
 // The 3 in the following line is the amount of lines below. So if another particle type is added to this list
 // the a += 3 should be changed to 4.
 for (var a = 0; a != shipControlScript.maxMissiles * explosionEventScript.numberOfParticles; a += 3) {
     particleArray[a] = Instantiate(explosionEventScript.explodePart01, Vector3(0,0,0),  Quaternion.identity);
     particleArray[a].active = false;
     particleArray[a+1] = Instantiate(explosionEventScript.explodePart02, Vector3(0,0,0), Quaternion.identity);
     particleArray[a+1].active = false;
     particleArray[a+2] = Instantiate(explosionEventScript.explodePart03, Vector3(0,0,0),  Quaternion.identity);
     particleArray[a+2].active = false;
 }
 print("Particle array loaded OK");

}`enter code here

Comment

People who like this

0 Show 0 · 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

Answer by Skuzzbag · Jun 27, 2011 at 05:17 PM

Ok I think I've found out what's happened but I don't know how to fix it.

I tried disabling the renderer and it still drew! So I checked the inspector and there is a mesh renderer in the prefab at the top level and a mesh renderer that is attached to the actual mesh and this isn't disabled.

I would have thought that anything done to the prefab at the top level would trickle down to meshes underneith it?

Comment

People who like this

0 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 qwertyp · Jun 27, 2011 at 05:25 PM 0
Share

Try SetActiveRecursively(false)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable/Enable Script or Add/Remove? 1 Answer

GameObject Static & Active Flags 1 Answer

How to disable gameobjects in code? 4 Answers

Disabling GameObject doesn't disable components 0 Answers

Children of DualTouchControls prefab keep being forced to active 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