- Home /
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.
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)?
@Skuzzbag - please don't post comments as answers. Ins$$anonymous$$d, post clarifications as comments or edits on your original post (until you gain the ability to comment on other users' answers). $$anonymous$$eeping the answer area tidy helps people see what's going on and where the dialogue currently stands.
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; }
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
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?
Your answer
![](https://koobas.hobune.stream/wayback/20220612123443im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how can i get a pause screen to work 0 Answers
If you disable a gameobject, does an InvokeRepeating loop end or pause? 3 Answers
Check if the child of an object is active not working!!! 2 Answers
"Prefab GameObject's can not be made active!" - Need a fix 1 Answer
How to find Inactive GameObject 16 Answers