Referencing Particle Emitter Options at Runtime

Hi all, first-time poster, long-time reader!

I’m trying to add components at run-time like so:

thrusters = GameObject.FindGameObjectsWithTag("Thruster");
	for (var thruster in thrusters) {
		var e = thruster.AddComponent("MeshParticleEmitter");
		var a = thruster.AddComponent("ParticleAnimator");
		var r = thruster.AddComponent("ParticleRenderer");
		a.sizeGrow = 1;
		e.InterpolateTriangles = true; !!
		e.SimulateInWorldSpace = false; !!
		e.localVelocity.x = -.2;
		var arr = new Array(Resources.Load("Materials/Fire1"));
		r.materials = arr.ToBuiltin(Material);
	}

But, as you can porobably see, my references to the Simulate in world space and interpolate triangles options aren’t valid. Can these be referenced programmatically?

Thanks!

Unfortunately not all properties are exposed to scripting. Instead of adding components, you can make a prefab set up the way you want and instantiate that.

–Eric

Thanks for the reply. Was afraid of that…

I don’t suppose I could set up a thruster prefab with the mesh particle emitter and then change the mesh property based on a variable, could I?

Yep, you can do that. The mesh emitter is kinda strange in that you reference the mesh from a MeshFilter component, rather than the ParticleEmitter component. In other words, changing the mesh in MeshFilter changes the mesh in the mesh particle emitter. (Which is good because you can’t access the mesh in the mesh particle emitter.)

–Eric

Working like a charm, thanks!

Isn’t there any way around this, since it’s available on JavaScript?

edit: answering my own question - http://answers.unity3d.com/questions/34196/how-to-create-particleemitter-in-code

ParticleEmitter emitter = (ParticleEmitter)gameObject.AddComponent("EllipsoidParticleEmitter");