How do I change the Skinned mesh renderer of a particle system at runtime?

126472-shapemodule.jpg
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.

You can set it through script

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;
    }