In August 2020, law enforcement officers from five agencies converged inside the hallways of a school in Uvalde, Texas, their guns drawn, role-playing how they would halt a gunman.

The training, detailed in documents reviewed by The New York Times, was part of an overhaul of security preparedness in Uvalde — and across much of Texas. Uvalde school officials were doubling their budget for security, updating protocols and adding officers to the district’s Police Department. And the city’s separate police force dispatched its SWAT team, in tactical gear, to learn the layout of school buildings.

But none of the extensive preparations halted the rampage of an 18-year-old gunman who entered a Uvalde elementary school this week and killed 19 children and two teachers. Family members who had rushed to the scene said they pleaded with officers, who were assembling outside the school, to enter the building.