trying to simply activate a particle emitter through script?

All I’m trying to do is enable a gosh darn particle emitter through a function, and the error it’s giving me is;

MissingReferenceException: The variable smoke of ‘alienTeleporter’ doesn’t exist anymore.
You probably need to reassign the smoke variable of the ‘alienTeleporter’ script in the inspector.
alienTeleporter.Landing ()

Now this is telling me that there is no smoke attached to the variable through the inspector. But I’m looking right at it, and yes, a particle emitter is attached to the variable “smoke”.

Code looks like this;

#pragma strict

import SmoothMoves;

var health:						int = 10;
var blastPower:					int = 5;

var smoke: 						GameObject;
var landing:					AudioClip;
var hover:						AudioClip;
var armsFold:					AudioClip;
var doorsOpen:					AudioClip;

var myAnimation: 				SmoothMoves.BoneAnimation;

private var soundRate 			: float	= 0.0;					// variable to hold sound rate
private var soundDelay			: float = 0.0;
private var isIdle				: boolean = false;
function Start ()
{
	myAnimation.RegisterUserTriggerDelegate(Landing);
	animation.Play("Land");
	yield WaitForSeconds (6.20);
	isIdle = true;
}

function Update ()
{	
	if (isIdle)
	{
		animation.Play("Idle");
	}
	if ( health <= 0 )
	{
		// stop spawner
		// print "level complete or some bullshit"
		// play win music
		// tally up reward for winning level
		// showcase any new item found
		// go to next level
		Destroy (gameObject);
	}
}

function OnTriggerEnter ( other : Collider )
{
	if ( other.gameObject.tag == "pigLauncher" )
	{
		Destroy (gameObject);
	}
	if ( other.gameObject.tag == "blastRange" )
	{
		health -= blastPower;
	}	
}

function Landing ()
{
	smoke.particleEmitter.enabled = true;
	PlaySound (landing, 0);
}

function PlaySound (soundName : AudioClip, soundDelay : float)						// calls to play sound based on sound file name attached to object
{
	if ( !audio.isPlaying && Time.time > soundRate )						// sets sound rate
	{
		soundRate = Time.time + soundDelay;									// option to add a delay to the sound before it starts playing
		audio.clip = soundName;
		audio.Play ();
	}	
}

thanks in advance, for any insight you may provide.

I've tried changing the smoke variable from a GameObject; to a ParticleEmitter;, with the same results. If I change it to ParticleSystem; it won't let me assign a particle system to it through the inspector...lol.

–

I think ParticleEmitter is not part of ParticleSystem. Former is legacy, latter is Shuriken. In shuriken you must 'Play' the system, not enable it.

–

Hey thanks for the heads up. What exactly do I change that line too then? I tried smoke. particleSystem.Play = true; as well as smoke.particleEmitter.Play = true; both cough out errors. And do I leave the variable as a GameObject, or do I change that to something else? ParticleEmitter; , maybe?

–

Its Play(); Added an answer with some script for you to dissect. :)

–

2 Answers

2

What I have is my main object, and on that object is a child object (called GravParticles) which contains the Particle System and a script (BlockConnectFire.js):

private var gravParticles : ParticleSystem;

function Start ()
{
	gravParticles = GetComponent(ParticleSystem); //retrieve the system
	gravParticles.Play();  //Fire the System
}

The child object is enabled, the script is disabled.

In a script on the main object I have:

private var connectParticles : GameObject;

function Start ()
{
	connectParticles = transform.Find("GravParticle").gameObject;
}

function OnCollisionEnter(blah)
{
     //Stuff
     connectParticles.GetComponent(BlockConnectFire).enabled = true; //Enables the script which contains the particle Play() call.
}

I'm not sure if this is the best way, but it worked for me. Note that I had Emission rate set to 0 and Burst particles set to one, for a one time 'halo' when my objects connect. Play on Awake, set to off. This example is using Shuriken Particle System.

–

Seeing this I was able to extract all the information I needed to get my script to work. I changed it from a GameObject; to ParticleSystem; and smoke.particleEmitter.enabled = true; to simply smoke.Play (); Works like a charm now! Thanks!

–

Glad I could help :)

–

I think you need to put
function landing ();

Somewhere in your script? say in your update or wherever needed

Before you can actually go using it??
Im not a genius with script so don’t be mad if I am wrong.

Also not sure if these help

ParticleEmitter.enabled

var enabled: bool;
Description
Turns the ParticleEmitter on or off.

A ParticleEmitter which is not enabled will not emit any particles, and the emitted particles will not animate. So, this value allows you to pause a particle emitter.
The default value is true.
	// Pause particle emitter.
	particleEmitter.enabled = false;

ParticleEmitter.emit

var emit: bool;
Description
Should particles be automatically emitted each frame?

	// Emit particles for 3 seconds
	particleEmitter.emit = true;
	yield WaitForSeconds(3);
	// Then stop
	particleEmitter.emit = false

http://docs.unity3d.com/Documentation/ScriptReference/ParticleEmitter.html

Sorry If this was absolutley Opposite of helpful… Goodluck!
There are actually two seperate codes there. the site decided to throw them together?
U might need to get component as well before you say emit true etc… Like I said Im not the best at coding. Im just proposing my novice suggestions :wink:

This is an example of Legacy particles.

–