Can't get ParticleSystem GetCustomParticleData/SetCustomParticleData to work

Hi all, I’m trying to use ParticleSystem GetCustomParticleData/SetCustomParticleData, I’ve had this working in 5.6 but don’t have the code in front of me.

I’ve tried this simple example from the Unity docs but when I step through the code GetCustomParticleData always returns vectors of 0,0,0,0

Has anyone tested this lately? I’m on 2017.1.0f3

Code:

using UnityEngine;
using System.Collections.Generic;

public class ExampleClass : MonoBehaviour
{

    private ParticleSystem ps;
    private List<Vector4> customData = new List<Vector4>();
    private int uniqueID;

    void Start()
    {
       
        ps = GetComponent<ParticleSystem>();
        UnityEngine.ParticleSystem.CustomDataModule customData = ps.customData;
        customData.enabled = true;

        customData.SetMode(ParticleSystemCustomData.Custom1, UnityEngine.ParticleSystemCustomDataMode.Vector);
        customData.SetVectorComponentCount(ParticleSystemCustomData.Custom1, 4);
        //customData.SetVector(ParticleSystemCustomData.Custom1, 0, 0);
        //customData.SetVector(ParticleSystemCustomData.Custom1, 1, 0);
        //customData.SetVector(ParticleSystemCustomData.Custom1, 2, 0);
        //customData.SetVector(ParticleSystemCustomData.Custom1, 3, 0);
    }

    void Update()
    {

        ps.GetCustomParticleData(customData, ParticleSystemCustomData.Custom1);

        for (int i = 0; i < customData.Count; i++)
        {
            // set custom data to the next ID, if it is in the default 0 state
            if (customData[i].x == 0.0f)
            {
                customData[i] = new Vector4(++uniqueID, 0, 0, 0);               
            }
        }

        ps.SetCustomParticleData(customData, ParticleSystemCustomData.Custom1);
    }
}

TNKS!

G

EDIT: Spoke too soon, trying to come up with a good test case to log a bug

TL;DT Solution: Setup custom particle data in Start not Awake

I worked it out. The above is a simple test which actually works. In my dev code I was setting up the custom data in Awake not Start. I think the Particle system wasn’t correctly initialed when I was trying to set properties on it.

The same happened to me GetCustomParticleData always returns vectors of 0,0,0,0, only returns the correct uniqueID
when GetCustomParticleData happened after SetCustomParticleData in the update.
why? Is this is a bug? I’m on 2017.3.0

YUP! I logged it a while ago:
https://issuetracker.unity3d.com/issues/setting-particlesystem-dot-customdatamodule-data-mode-to-vector-or-color-causes-getcustomparticledata-slash-setcustomparticledata-to-fail

Though it was closed “By Design” :rage::rage::rage::rage::rage::rage::rage::rage:

Just added it as a feature request we can vote on:
https://feedback.unity3d.com/suggestions/set-and-get-custom-color-and-vector-data-for-particle-systems