Particle effect spawned lags behind parented object

I have a gun barrel and I spawn a particle effect at the end of it when the gun fires. Everything’s OK when the gun isn’t moving, but if the player does move, the effect is spawned, but is offset from the barrel.

I have the effect in the scene and I use Instantiate() to create a copy of it. I then set the transforms like so:

effect.transform.parent = spawnPoint.transform;
effect.transform.localPosition = Vector3.zero;

Where ‘spawnPoint’ is the end of the barrel. I’ve stepped through the code and everything looks OK. This also effects anything else spawned from this point. E.g. bullets. They look like they’re firing from outside the gun when the player is moving.

The spawnPoint obviously isn’t correctly set, then. I assume this is an empty Game Object somewhere within your character hierarchy? Double check what it is parented to - it’s very important.

Probably the parent of that game object is wrong and it needs to be moved to a node that controls the gun position (or something similar, depends on your setup).

To debug, simply place a small cube or whatever at the spawnPoint and see what happens in the game, how does it move. Re-parent it and try again.