Search Issue Tracker

Won't Fix

Votes

1

Found in

2018.4

2018.4.29f1

2019.4

2020.1

2020.2

2021.1

2021.2

Issue ID

1299919

Regression

No

Old Particle System's Custom Data is used when SetParticles() is called before SetCustomParticleData()

Visual Effects - Legacy

-

How to reproduce:
1. Open the user's attached "Psys_Custom_Data_Issue.zip"
2. Open the "Psys_Custom_Data_Bug" Scene
3. Enter Play Mode
4. Observe the Console log

Expected result: Data for Particle System with ID 2 is printed in the Console log "customParticleData[0] = (2.0, 0.0, 0.0, 0.0)"
Actual result: Data for Particle System with ID 1 is printed in the Console log "customParticleData[0] = (1.0, 0.0, 0.0, 0.0)"

Reproducible with: 2018.4.30f1, 2019.4.17f1, 2020.1.17f1, 2020.2.0f1, 2021.1.0a10, 2021.2.0a1

  1. Resolution Note (2021.2.X):

    This is an awkward edge case behaviour.
    We have a rule in the particle code that when the remainingLifetime <= 0, the particle gets removed. The docs actually say this happens when the value is < 0, but it's too risky for other uses cases, to change this in the code.

    So, what happens, is, in your script, your first particle ends up with a remainingLifetimee of exactly 0.
    You call SetParticles, it gets removed, and the custom data gets reorganised, then you call SetCustomParticleData, but that array has 2 values in it. So it sets invalid data. But you have no good way of knowing that the internal Unity code killed the first particle and reorgnaised the data+custom data.

    I'm kinda guessing that your test code is simplified just to demonstrate the problem, but I can suggest 2 workarounds to deal with this:
    1. You don't modify the particles data, so don't call SetParticles at all (might be just because you simplified the script for the bug report tho!)
    2. Do the assignment of the custom data IDs before calling SetParticles. This will ensure that SetParticles doesn't mess with the particle data before you assign the ID.

    For option 2, I notice you've already suggested that exact thing in your example script.
    I'm also going to add an error message to Unity to point out this problem far more clearly (ie if you set more custom data than you have particles). This should make it more obvious in the future.

    Thanks for taking the time to send the report!

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.