x


Particle Emmitter not working

Hi, my problem is simple (please be patient, my knowledge of Unity isn't too extensive). I have a turret gameObject which has 2 pieces, the head and base. The turret has to aim automatically at "zombies" that walk through a trigger that has been attached to the parent object. There are two scripts attached to the head: AimTurret and TurretParticleController.

AimTurret:

var target : Transform;

var aiming = false;

function Aim(newTarget : Transform)

{

target = newTarget;

transform.LookAt(target);

aiming = true;

}

function Return(original : Transform)

{

target = null;

transform.LookAt(original);

aiming = false;

}

function isAiming()

{

return aiming;

}

TurretParticleController:

function Start () 

{ var aimControl : AimTurret = GetComponent(AimTurret);

//Establish link to particle emitter and deactivate emission.
var particles : Component[] = GetComponentsInChildren(ParticleEmitter);
for (var p : ParticleEmitter in particles)
{
    p.emit = false;
}

//Once every frame update and check status.
while(true)
{
    var isAiming = aimControl.isAiming();

    for (var p : ParticleEmitter in particles)
    {
       p.emit = isAiming;
    }

    yield;
}

}

The aiming is working fine, and isAiming is also perfect. However when I run this, I get the following error:

MissingReferenceException: The object of type 'ParticleEmitter' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

I don't know what I am supposed to do to fix it, and my particle emitter isn't switching on and off like I want it to when the "Zombie" is inside the collider.

Thanks in advance for your help

more ▼

asked Aug 04 '11 at 06:51 PM

greyes1990 gravatar image

greyes1990
1 1 1 1

Do you still get the error if you comment out the line "p.emit = false;" ? Because else this could be the same as lights, when you disable a light you cannot access it anymore. Maybe if you disable particle emission from a particle emitter, it cannot be accessed again.

Im only guessing, thats why this is not in the answer section.

Aug 07 '11 at 11:42 PM MrcDesign

I have exactly the same problem. If I try to set the emit property to false, the emitter seems to disappear (after the last particle has died out, I believe). How are you supposed to be able to turn particle emitters on and off if this destroys the object? The enabled property works, however that just turns the GameObject on and off and leaves the particles suspended in mid-air, which looks silly. I hope there is a solution to this or it can be fixed.

Aug 17 '11 at 04:07 PM Daveoh
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Ensure that Autodestruct is not enabled in the Particle Animator, which will destroy the entire GameObject when all particles have died out, shortly after turning off emissions.

http://unity3d.com/support/documentation/Components/class-ParticleAnimator.html

more ▼

answered Aug 21 '11 at 12:44 PM

Daveoh gravatar image

Daveoh
128 1 2 5

Thank you very much!

Didn`t let me to give you thumbs up, don`t know why :/

Nov 18 '12 at 04:45 PM apomarinov
(comments are locked)
10|3000 characters needed characters left

You probably have One Shot enabled on the particle emitter. If you have, it'll fire all particles at once, instead in a constant stream, and then destroy itself. Either turn this of, or keep creating a new one for every 'shot'.

more ▼

answered Aug 17 '11 at 10:22 PM

Joshua gravatar image

Joshua
6.4k 19 25 71

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x30
x15

asked: Aug 04 '11 at 06:51 PM

Seen: 1193 times

Last Updated: Nov 18 '12 at 04:45 PM