- Home /
Particle system playing but not emitting any particles.
So I have a very strange issue. In my game I have players with particle systems that emit as they move and use the ribbon function in order to simulate a trail (using this method over trail renderer so I can tap into particle collision events). There is also screen wrap in the game for the player characters, and in order to get this work without drawing a ribbon between opposite ends of the screen on a player's wrap I unparent the current particle system on the initial side of the screen, set it to destroy when it's finished, and instantiate a new one parented to the player on the other side of the screen. The strange bit is that, under certain conditions, the newly instantiated system will not emit any particles. Here is a list of features of this issue that confound me:
-If I pause the game and restart it, or if I highlight anything in the hierarchy, the particle system begins emitting like normal until I wrap again. Sometimes the particle system just works too. It's not always broken.
-This only occurs when I wrap from the bottom of the screen, and if I instead jump to the top and wrap it will instantiate a system that works fine.
-The newly instantiate particle system is playing and is in the correct position, but when the game is paused and it's highlighted it shows that 0 particles are being emitted even though the emission module's rate over distance is set to 10. If I log the particle systems states it says it's playing and emitting even when no particles are being emitted.
I've tried several hacky solution attempts including setting the particle system prefab inactive and setting it active in code, setting the system to NOT play on awake then telling it to play once instantiated, etc, but none of them works whatsoever.
Here is the code for the particle instantiation:
//this function checks to see if the player should wrap and calls the wrap funtion
private void CheckForWrap()
{
if(transform.position.x < leftConstraint)
{
TriggerWrap();
transform.position = new Vector3(rightConstraint, transform.position.y, 0f);
}
else if (transform.position.x > rightConstraint)
{
TriggerWrap();
transform.position = new Vector3(leftConstraint, transform.position.y, 0f);
}
else if (transform.position.y > topConstraint)
{
TriggerWrap();
transform.position = new Vector3(transform.position.x, bottomConstraint, 0f);
}
else if(transform.position.y < bottomConstraint)
{
TriggerWrap();
transform.position = new Vector3(transform.position.x, topConstraint, 0f);
}
}
//this function runs in the character controller when a screen wrap is detected
public override void TriggerWrap()
{
currentTrail.transform.parent = null;
var main = currentTrail.GetComponent<ParticleSystem>().main;
main.loop = false;
main.stopAction = ParticleSystemStopAction.Destroy;
currentTrail = Instantiate(trailPrefab, trailSlot.transform.position, Quaternion.identity, trailSlot.transform);
currentTrail.GetComponent<PlayerTrail>().AttachToPlayer(this);
}
Here is the code that is attached to the particle system and run when a new prefab is instantiated from the character controller:
//this is the function that is called when a new particle system is instantiated
public void AttachToPlayer(PlayerController pc)
{
player = pc;
ParticleSystem.CollisionModule collisionModule = trailParticleSystem.collision;
LayerMask layer0 = 1 << LayerMask.NameToLayer("Player0");
LayerMask layer1 = 1 << LayerMask.NameToLayer("Player1");
LayerMask layer2 = 1 << LayerMask.NameToLayer("Player2");
LayerMask layer3 = 1 << LayerMask.NameToLayer("Player3");
switch (player.GetID())
{
case 0:
collisionModule.collidesWith = layer1 | layer2 | layer3;
break;
case 1:
collisionModule.collidesWith = layer0 | layer2 | layer3;
break;
case 2:
collisionModule.collidesWith = layer0 | layer1 | layer3;
break;
case 3:
collisionModule.collidesWith = layer0 | layer1 | layer2;
break;
default:
break;
}
}
Here is a screenshot of the particle system prefab that is used:
Any help would be appreciated!
Answer by ElanaHonor · Nov 20, 2019 at 10:43 AM
try to change the child (the particle) position from 0,0,0 to small amount like 0.1,0.1,0.1 hope that will save your problem as it solved mine
Your answer
Follow this Question
Related Questions
Emit Particles based on rotation speed 0 Answers
Cannot turn ParticleSystem on/off, and it keeps randomly disappearing. 1 Answer
Particle System Sprite Randomization 1 Answer
my partical fade away when the emitter moving fast ? 0 Answers
Particles emitted from texture not appearing in game build. 1 Answer