Unity Particle System scripting mesh emitting

unity
particles
vfx

#1

Does anyone have the code or script to spawn particles on a mesh unity in unity, so that only one particle spawns on each vert?

I cant seem to make this happen with the current interface. the best i can do is turn of random seed and set a seed that spawns a particle on each vert. but then i get the same “look” every time the particle system plays, which is not ideal. I know a script would work. but thought i’d check to see if anyone has already made one?

cheers


#2

pretty much working version of the script to spawn a particle on each vert… though it sounds like this will be a native feature soon anyway

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class particlescript : MonoBehaviour {

private ParticleSystem ps;
public Mesh myMesh;
void Start()
{

	this.ps = this.GetComponent<ParticleSystem>();

}
void OnEnable(){

	DoEmit();
}

void DoEmit()
{

	

    var emitParams = new ParticleSystem.EmitParams();
    
	Vector3[] verteces =   myMesh.vertices;
	
	Vector3[] particleDirection = myMesh.normals;
	int count = myMesh.vertexCount;
	for (int i = 0, ic = count; i < ic; i++)
			 {
				verteces[i] = Vector3.Scale(verteces[i],this.transform.localScale);
				emitParams.position = myMesh.vertices[i];
				emitParams.velocity = Vector3.Scale(verteces[i],new Vector3 (1.1f,1.1f,1.1f));
			//	Debug.Log( verteces[i].ToString("F4"));
				 ps.Emit(emitParams, 1);

			}
   
    ps.Play(); 

}

}