- Home /
Shuriken Particle System - Accessing the emitter mesh through script
Hi there,
I have been looking everywhere for this, but to no avail. Basically, how do you access the mesh variable within the shape module on the new Shuriken particle emitters? The current documentation on Shuriken in the script reference (here: http://unity3d.com/support/documentation/ScriptReference/ParticleSystem.html) has no reference to variables in other modules other than the Initial Module.
The reason I'd like to access it through script is because I am wanting to procedurally generate meshes for volumetric cloud systems. If there is actually no way to access it, well I suppose I'd need to go back to the drawing board ...
Sorry for the long post size ... I'm not great at being succinct! :D
Thanks very much, Klep
So is there absolutely no way to access this variable?
I know that this will be a shameless BU$$anonymous$$P, but this still affects me. $$anonymous$$aybe it has some relevance now that 3.5 has been out for quite some time?
well, I dont want to dissapoint you, but, you cant, i had the same problem, BUT , it will be added soon as I read in unity forums from the Unity HQ Coppenhagen : "In the next release of Shuriken this will be possible. Shuriken will use the transform.scale for emitter size."
If you're just trying to dynamically change the scale of the effect you can do this with an animation curve that modifies the scale properties of the emitter. You can create an animation that blends between your $$anonymous$$imum and maximum size, and then procedurally set the current time of the animation (AnimationState.normalizedTime) to select the desired scale. A little indirect, but it works for the particular use case of resizing the effect.
Answer by Benoit Dufresne · Mar 07, 2013 at 07:01 PM
I'm using Unity 4, and this doesn't seem to be in yet. I can't find documentation for it either.
I'm fairly annoyed that "legacy" is used to describe the only fully-functional particle system. I would have gone with the old system from the get-go with if wasn't called "Legacy" and Shuriken was called "Beta" instead.
Answer by kat0r · Feb 21, 2014 at 07:29 PM
If you still want it, and because there was a reply 10days ago:
SerializedObject so = new SerializedObject(GetComponent<ParticleSystem>());
so.FindProperty("ShapeModule.m_Mesh").objectReferenceValue = myMesh;
so.ApplyModifiedProperties();
May require "using UnityEditor;"
You can basically access everything in the ShurikenSystem with that, see: http://answers.unity3d.com/questions/483831/how-to-modify-particlesystem-from-editor-script.html
Not "may require 'using UnityEdtior'"
As of Unity4.5, SerializedObject absolutely will require the UnityEdtior namespace and therefore will not compile.
Answer by Corngood · Oct 10, 2013 at 12:37 AM
Shuriken seems to deal with the mesh being modified at runtime, so I've just created an empty mesh asset, hooked it to both the emitter and the script component which creates the vertices. It's a silly hack for something that should have been exposed, and I haven't found a way to get multiple instances of a emitter prefab with unique mesh data.
Something I noticed was that it will only emit for vertices on triangles, so I've had to create fake triangles for my point cloud. Setting indices with 'point' topology caused Unity to crash (4.2.1).
Hey,
I've been trying to get a particle emitter to emit from a procedurally generated mesh (a point cloud that I'm reading into unity from a text file), and it sounds like you found a way to do that but I'm confused about the fake triangles. Are you setting them manually or doing it in scripting? I really appreciate any help you can give me. Do you have any code I could look at?
Thanks!
We just add points and triangles to the mesh like this:
mesh.vertices = points;
var triangles = new int [(points.Length + 2) / 3 * 3];
var j = 0;
for (; j < points.Length / 3 * 3; ++j)
triangles[j] = j;
for (; j < triangles.Length; ++j)
triangles[j] = points.Length - 1;
mesh.triangles = triangles;
I haven't looked at this since Unity 4.3, so it's possible that things have been fixed/improved.
Hey,
Thanks so much! I'm checking to see if anything has improved, but that got me up and running for now.
Answer by syslord2k2 · Nov 25, 2013 at 04:04 PM
You can access the mesh component of the Shuriken Renderer section by accessing the ParticleSystemRenderer component like this (c#)
gameObject.GetComponent<ParticleSystemRenderer>().mesh
@ syslord2k2
That is to access the mesh that is being rendered, not the one being used as an emitter in the shape module. So that doesn't work.