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 )?
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.
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?
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