An article I skimmed in the last few days noted that most of the US shootings in recent years have been by mentally ill individuals that have been on very potent psychoactive drugs. Change the dosage on those or stop taking them abruptly and people can dive right over a cliff. Couple that with a person that has social issues and plays FPS video games and bad things can happen.
Authorities had been told that he was threatening to do something like this and had the rifle. The FBI admitted they didn't follow up. It's a breakdown all up and down the chain. Of course, the FBI is currently going through a period of not knowing what is and isn't against the law.