- Home /
Simple Particle to turn on and off button press is breaking inconsistently. (After Building to Windows)
Hey,
So I've got a spaceship that flies about with a thruster particle and sound (looped) that both play when the key presses down and stop when I release it. For a while they've been working fine but today it seems like really inconsistently either they both wont work on the button press, one wont work and the other will or they'll both work fine. I'm also getting it so the particle wont turn off after letting go of the button until the next press resets it. I've also got some stuff happening when I'm on Input.GetKey as well as the GetKeyDown and GetKeyUp functions. All of the other functionality works fine. The ship moves fine etc as it should, it's just the sound and particle. And they were working before and from what I can tell should be now and do work fine probably 60% of the time.
This is just on Windows Builds. All is fine in editor.
I know that having lots of sounds in a scene (there's probably 4 or 5 firing off at certain points) can affect audio playing but my concern lies more with the particle randomly doing whatever it wants!
Code:
if (!gh.inDialogue && !gh.inTutorial) {
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (hasFuel)
{
thrusterSound.Play();
thrustPS.Play();
}
}
if (Input.GetKey(KeyCode.UpArrow))
{
if (hasFuel)
{
rb.AddRelativeForce(Vector2.up * speed);
gh.fuel--;
gh.FuelBarUpdate();
FuelCheck();
}
else
{
if (notShowingText)
{
gh.noFuelSound.Stop();
gh.noFuelSound.Play();
StartCoroutine("NoFuel");
}
}
}
if (Input.GetKeyUp(KeyCode.UpArrow))
{
thrusterSound.Stop();
thrustPS.Stop();
}
This is in fixed update.
The middle section on GetKey is all consistently work 100% fine. Anyone have any ideas about why a build version would stop consistently turning on and off sounds and particles? Is there a setting for builds I've missed?
Thanks in advance! :)
Answer by benwrightdesign · May 13, 2020 at 02:19 PM
Ok, so I've fixed this now. Turns out that it was a combination of events being called between Update and Fixed Update. I had my physics stuff on Fixed update which is calling at a different speed to Update so I'm assuming that's what threw it off as it was accessing things on update that were changing at different speeds.
So, in short, make sure nothing is needed in both Fixed Update and Update as their frame rates wont always match up and it may not show until you build!
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Particlesystem only emitting once 1 Answer
Inconsistency between builds. 0 Answers
Particle System + Audio Source sync? (specifically sub effect) 0 Answers