Getting ahold of Ellipsoid Particle Emitter member

I’m trying to modify the Ellipsoid ( as seen from the inspector ) member of an Ellipsoid Particle Emitter component. I can grab most/all the other members by just using it as a ParticleEmitter…

var particleSystemA = GameObject.Find(“Particle System A”);
var emitterA=particleSystemA.GetComponent( ParticleEmitter ) as ParticleEmitter;

If I am more specific and try to grab it “as” an EllipsoidParticleEmitter the script does not think that it is a valid type.

Do I need to #include something ( or however you do such a thing in javascript )?

I’ve had this problem myself. As far as I can tell, the ellipsoid is impossible to change by script.

There isn’t EllipsoidParticleEmitter (or MeshParticleEmitter either), only ParticleEmitter. Not everything is exposed to scripting unfortunately.

–Eric

Were there any script changes in 2.5 to expose properties like UnityEngine.ParticleEmitter.oneShot?

I don’t see a way to modify this property with script for EllipsoidParticleEmitter or MeshParticleEmitter.

I filed a few bugs about this.

The particle classes need to be exposed and made public.

it seems this problem still remains…

same problem, still no fix :frowning:

This:

EllipsoidParticleEmitter emitter = gameObject.AddComponent<EllipsoidParticleEmitter>();

Gives me this error:
error CS0246: The type or namespace name `EllipsoidParticleEmitter’ could not be found.

And this:

ParticleEmitter emitter = gameObject.AddComponent<ParticleEmitter>();

Gives me this error:
Cannot add component of type ‘ParticleEmitter’ because it is abstract. Add component of type that is derived from ‘ParticleEmitter’ instead.

How can I add a ParticleEmitter component to a GameObject through scripting?
~ce

Only a guess, but if you find out whats the full typename of the EllipsoidParticleEmitter is you can do this:

var emitterType = Type.GetType("UnityEngine.EllipsoidParticleEmitter"); // only a guess for the typename
var methodInfo = gameObject.GetType().GetMethod("AddComponent");
var genericMethodInfo = methodInfo.MakeGenericMethod(emitterType);
genericMethodInfo.Invoke(gameObject , null);

Not tested and probably it will not work, but its worth a try.

To get the full typename:
Create a GameObject with an attached EllipsoidParticleEmitter and add a new script which basically does this in the Start() function:

var particleEmitter = GetComponent<ParticleEmitter>();
Debug.Log(particleEmitter.GetType().FullName);

The full typename will then be displayed in the log console. If only something like “ParticleEmitter” is displayed it wont work, in this case Unity does something else, but I dont believe it because ParticleEmitter is a mere abstract class and need to be inherit by a concrete class.

Unfortunatly it only returns: UnityEngine.ParticleEmitter
:frowning:

Would be very nice if UT would expose this to scripting, I see requests for this are going years back.

So we still can’t modify ellipsoid particle emitters?

Why yes you can…

gameObject.AddComponent("EllipsoidParticleEmitter");

The quotes are the key.

BigMisterB,
the problem of this thread is accessing the EllipsoidParticleEmitter specific members.
How would you go about accessing the members after having added the component?

You can’t. It sucks, and it should be fixed. But you can’t. I do not think you can even use reflection to do it.

“I do not think you can even use reflection to do it.”

You actually can acces most members of particle emmiters. In my PlaySave script (keep runtime changes) I’m able to acces most members by:

your_particle_emmiter.GetType().GetProperties()
and
your_particle_emmiter.GetType().GetFields()

I do agree that unity should make them accessible easier though.

Are you sure? I know that theres some things you can access but not all.

The settings are serialized. So you should be able to browse the settings using SerializedProperty /SerializedObject but those are in UnityEditor namespace.

On a up note though, they are redesigning the particle systems in 3.5. Hopefully they’ll fix it to expose all members before adding in something like speech recognition, brainwave analysis, or you know self writing code.

@BDev: Sorry, you are right. Some variabeles still can’t be accessed. You can acces quite a few though. And don’t you think brainwaves are absolutely essential to game developing?

If anyone still cares about this on this thread or future people who see this just use
gameobject.GetComponent(“EllipsoidParticleEmitter”).particleEmitter. etc to access members

2 Likes

ha, just figured this out (needs to be higher in the form)