- Home /
Question by
StarkRaven · Oct 22, 2018 at 03:14 AM ·
particlesparticlesystemskinnedmeshrendererparticle-system
How do I change the Skinned mesh renderer of a particle system at runtime?
I can not seem to find an answer to this question. I am trying to set the skinned mesh renderer of a particle system with an instantiated mesh.
shapemodule.jpg
(22.4 kB)
Comment
Answer by karl_jones · Oct 23, 2018 at 10:53 AM
You can set it through script https://docs.unity3d.com/ScriptReference/ParticleSystem.ShapeModule-skinnedMeshRenderer.html
Obviously you can set it though script. I was looking for an answer that describes how exactly.
Answer by StarkRaven · Oct 24, 2018 at 05:03 PM
I figured out how to get it to work. You can try something like this.
using UnityEngine;
public class TailSparkles : MonoBehaviour
{
public GameObject mesh; //game object that will be the particle system mesh
public GameObject pSystem; //particle system
void Start()
{
Instantiate(pSystem);
Instantiate(mesh);
var psystemClone = GameObject.Find("The name of your particle system");
var myMesh = GameObject.Find("The name of your mesh").GetComponent<SkinnedMeshRenderer>();
ParticleSystem ps = psystemClone.GetComponent<ParticleSystem>();
var sh = ps.shape;
sh.enabled = true;
sh.shapeType = ParticleSystemShapeType.SkinnedMeshRenderer;
sh.skinnedMeshRenderer = myMesh;
}