- Home /
Manually positioned particles disappearing when origin is outside camera view in build only
I am manually setting the positions of particles in a particle system. In the editor, they work as expected. However, when I build to PC and run the built executable, the particles disappear when the origin of the world space (0,0,0) is outside the camera view.
I have read dozens of threads with related problems, but this seems distinct.
I've isolated the problem with a test project. Here is the very simple code of the script attached to the object with the particle system:
using UnityEngine;
using System.Collections;
public class ParticleManager : MonoBehaviour {
ParticleSystem myParticleSystem;
private int numPoints = 5000;
private ParticleSystem.Particle[] points;
// Use this for initialization
void Start () {
myParticleSystem = GetComponent<ParticleSystem>();
points = new ParticleSystem.Particle[numPoints];
for (int i = 0; i < numPoints; i++) {
float initialOffset = i * 0.1f;
//points[i].position = new Vector3(initialOffset, 0f, 0f);
points[i].position = new Vector3(Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f), Random.Range(-10f, 10f));
points[i].color = new Color(1, 0f, 0f);
points[i].size = 0.1f;
}
}
// Update is called once per frame
void Update () {
myParticleSystem.SetParticles(points, points.Length);
}
}
In my scene, there are only two objects, the main camera and the object with the particle system.
The main camera has default settings. I haven't changed anything there.
The issue is reproducible with these settings for the Particle System (probably with any settings, but I can vouch for these settings for sure as they're in place as I type this): Duration: 5 Looping: false Prewarm: false Start Delay: 0 Start Lifetime: 0 Start Speed: 0 Start Size : 1 3D Start Rotation: false Start Rotation: 0 Randomize Rotation Direction: 0 Start Color: 1, 1, 1, 1 Gravity Modifier: 0 Simulation Space: World Scaling Mode: Local Play On Awake: false Max Particles: 1000
All the Particle System nodes are off except for Renderer. The Renderer settings are: Renderer Mode: Billboard Normal Direction: 1 Material: Default-Particle Sort Mode: By Distance Sorting Fudge: 0 Cast Shadows: off Receive Shadows: false Min Particle Size: 0 Max Particle Size: 0.5 Sorting Layer: Default Order in Layer: 0 Billboard Alignment: View Pivot: 0, 0, 0 Reflection Probes: off
Also, Resimulate and Wireframe are false
I've tried LOTS of things to make this work. I've tried setting simulation space to local, turning on resimulate and wireframe, making sure my object transform scale is 1, trying large and small transform scale, trying non-uniform transform scales. It even happens when I set the simulation space to local and parent the particle simulation to be in front of the camera. The particles follow the camera until the world origin is out of view, then they disappear. So, it doesn't seem to have anything at all to do with the particle system transform. This is not an exclusive list. I've tried everything I read in archives, but nothing worked.
And I repeat, this ONLY happens when the game is built, it does not happen at all in the editor.
Can anyone give any suggestions? I've run out of ideas at this point and I seem to have exhausted the archives.
This is in Unity 5.3.3f1. I've tried it on two separate computers (Windows 8 and 10) and in two separate projects.
Answer by karl_jones · Mar 30, 2016 at 09:21 AM
Sounds like a bug with culling and the AABB. Can you try the latest version of Unity 5.3.4~ If you still have the problem file a bug report and send me the number so i can take a look.
Follow up, this is FIXED in 5.4.0b12, the current newest Beta version at the time of writing this.
Its possible that it is something that is currently being backported to 5.3. Ill look into it
Have you tried the latest 5.3? http://unity3d.com/unity/qa/patch-releases
I tried with 5.3.4f1 and it was not fixed as of that release.
Did you try the Beta release? As noted above, if I built my project from the newest Beta, this was not a problem.
Unfortunately I am not interested in beta version as we have to release our game on S$$anonymous$$m this month and can't risk it
problem is only in build...code is classic infinity star for particle system: using UnityEngine; using System.Collections;
public class Infinite_Starfield : $$anonymous$$onoBehaviour {
private Transform tx;
private ParticleSystem.Particle[] points;
public int stars$$anonymous$$ax=100;
public float starSize=1;
public float starDistance=10;
public float starClipDistance=1;
public Color _Colors = new Color(0.8f,0.8f,1,0.8f);
private float starDistanceSqr;
private float starClipDistanceSqr;
private ParticleSystem ps;
void Start () {
//tx = transform;
tx = Camera.main.transform;
starDistanceSqr= starDistance*starDistance;
starClipDistanceSqr=starClipDistance*starClipDistance;
ps = GetComponent<ParticleSystem>();
points = new ParticleSystem.Particle[stars$$anonymous$$ax];
for (int i = 0; i < stars$$anonymous$$ax; i++)
{
points[i].position = Random.insideUnitSphere * starDistance + tx.position;
points[i].startColor = _Colors;
points[i].startSize = starSize;
}
// StarPosition();
}
// Update is called once per frame
void Update () {
StarPosition();
}
void StarPosition()
{
for (int i = 0; i < stars$$anonymous$$ax; i++)
{
float magnituda = (points[i].position - tx.position).sqr$$anonymous$$agnitude;
if (magnituda > starDistanceSqr)
{
points[i].position = Random.insideUnitSphere.normalized * starDistance + tx.position;
points[i].startSize = starSize;
}
if (magnituda <= starClipDistanceSqr)
{
float percent = magnituda / starClipDistanceSqr;
points[i].startSize = percent * starSize;
}
}
ps.SetParticles(points, points.Length);
}
}
Ok I know this bug. Its the bounding box not being updated when using SetParticles. It is on the way to 5.3 at the moment.
This isn't an answer, so please be careful about how you're posting. You could start a new Question, or start a forum thread, or as $$anonymous$$arl asked you to, you could submit a bug report.
Answer by richardkettlewell · Apr 13, 2016 at 09:35 AM
We are backporting a fix for http://issuetracker.unity3d.com/issues/shuriken-is-culling-particles-when-were-using-setparticles, which will be available in 5.3.4p4, which should hopefully fix this issue for you.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Game preview incorrect! 0 Answers
Camera Changes Proportions In Build 1 Answer
Overlapping particle systems 0 Answers
Linux build only displays colours 0 Answers