When did the bayonet go from something that was always attached in combat to something that was only brought out for special occasions?

by hborrgg

As I understand it, bayonet combat was already rare by the Napoleonic wars, yet it was still the norm for troops to march into battle with their bayonets already attached. When did the bayonet become something that soldiers only fixed to their rifles in specific situations, for instance right before their commander orders a charge?

Casiphoner

As a followup question, in WW2 Pacific Theatre Games like Call of Duty World at War, we see both US and Japanese soldiers use bayonets frequently. Is this true for the Pacific Theatre or is this anachronistic?