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.

The carnage has renewed a decades-old debate about how to end the horror of U.S. school shootings, with many Texas political leaders once again calling for heightened school security measures. But others, pointing to devastation even on campuses that have invested heavily in security, said that such a singular focus could not stop a committed killer with access to weapons — and that such efforts might actually provide a false sense of safety in the absence of gun control regulations and more robust investments in mental health.

After the shooting at Columbine High School in Colorado in 1999, Congress began providing federal dollars for campus officers, and officials made — and remade — security protocols inside schools, from lockdown training drills to elaborate identification requirements. Nationally, 19% of elementary school students, 45% of middle schoolers and 67% of high school students attend a school with a campus police officer, according to a 2018 report from the Urban Institute.

Still, there is little evidence nationally that the dollars poured into school security measures have decreased gun violence in schools, according to a 2019 study co-written by Jagdish Khubchandani, a professor of public health at New Mexico State University.

"These security measures are not effective," Khubchandani said this week. "And they are not catching up to the ease of access with which people are acquiring guns in the pandemic."

The nation's epidemic of school shootings has only grown worse, sometimes in situations where armed school officers have been present. An officer on duty at Marjory Stoneman Douglas High School in Parkland, Florida, in 2018 has been accused of hiding as a teenage gunman killed 17 people.

After a shooting at a high school in Santa Fe, Texas, left 10 people dead in 2018, state leaders pressed new plans aimed at enhancing school security. The plans emphasized detecting mental health troubles, expanding monitoring of social media for threats, providing training on shootings and increasing the presence of law enforcement officers at schools. Across the state, $100 million was budgeted for upgrades such as metal detectors, security systems, two-way radios and bullet-resistant glass.

Uvalde, a small community not far from the U.S.-Mexico border, was among the beneficiaries, getting a grant for $69,141.

About the same time, the school district was building up its own security. It hired two new police officers last year, expanding to a six-person force that serves about 4,000 students across several schools. The school system's spending on security and monitoring services more than doubled in the past four years, budget records show.

The district's security plan included two-way radios, threat assessment teams at each school and a policy of locking each classroom door. At Robb Elementary School, where the rampage took place Tuesday, officials described fencing enclosing the campus that was "designed to limit and/or restrict access to individuals without a need to be on the campus," district records said.

The school district's security training exercises in August 2020 included its own police officers, the Uvalde city police, the county sheriff's office and other local agencies.

"It was very successful," Pete Arredondo, chief of the school district's police force, wrote in a summary for district officials.

Officials from the school district did not respond to messages seeking comment Thursday.

Details of the massacre inside Robb Elementary were still emerging, but officials have provided a timeline of events in which they said that a school district police officer headed to the school after 911 calls came in around 11:30 a.m. Tuesday. After the officer arrived, the gunman — who had scaled a fence to enter the parking lot — fired at the school and then entered it, according to the timeline. At some point, at least two members of the Uvalde Police Department entered the school, officials said, but they were shot and retreated.

About 90 minutes after the initial 911 calls, officials said, agents of the U.S. Border Patrol entered the building and killed the gunman.

Since the Columbine killings more than two decades ago, law enforcement training for shooting situations has evolved considerably. At the time, the emphasis was on making sure that officers secured a perimeter before moving in. Officers are now trained to disable a gunman as quickly as possible, without waiting for a tactical team or special equipment to arrive and before rescuing victims.

The approach changes if the gunfire stops, as it did in the Pulse nightclub shooting in Orlando, Florida, in 2016, when the gunman barricaded himself in the bathroom with several victims. Barricaded hostage situations can be complex. In the nightclub shooting, the gunman, on the phone with crisis negotiators, claimed that he had explosives. At the same time, wounded victims needed treatment. When officers breached a bathroom wall, the gunman began firing again.

Mo Canady, executive director of the National Association of School Resource Officers, said that school officers had prevented many instances of violence that do not gain broad attention. He pointed to a National Policing Institute database that showed 120 cases of averted school violence between 2018 and 2020.

Canady said that his organization had trained several Uvalde school officers over the course of four years but that they were typically based at secondary schools, not elementary schools. He warned against jumping to conclusions about officers' actions Tuesday.

Storming a building too quickly could allow a gunman to escape, he said. And while capturing or killing a gunman is "Plan A," he said, containing the person to a particular space can be an effective "Plan B" to lessen the carnage.

The Texas Rangers have been investigating how local police officers responded to the shooting as part of a broader investigation into the massacre, state officials said Thursday.

The Uvalde school district, like many across the country, was also using measures connected to students' well-being in its efforts to prevent violence, documents showed. The district used software called Social Sentinel, which monitors students' social media posts for threats, and an app called STOPit, which allows anonymous reports of bullying.

Ron Avi Astor, an expert on school violence at UCLA, said that while emotional supports have improved school climate broadly, those strategies — as well as the presence of campus police officers — have been insufficient to prevent suicidal, deeply troubled young men from carrying out attacks.

The focus, he said, should be on referring high-risk individuals to mental health treatment while preventing them from buying or owning guns.

"We have to start talking about shooters and shootings differently," he added.

Like the schools in Uvalde, most schools in the United States hold lockdown drills. While some survivors of last year's shooting at Oxford High School in Michigan credited the trainings with helping them quickly escape the building, there is little evidence that the drills mitigate risk — and lots of concern from parents, educators and mental health experts that they cause fear and anxiety for children.

There are some simple, inexpensive measures that are protective, according to those who have studied school shootings. One of them is keeping classroom doors locked, which was a district requirement in Uvalde.

It is not clear whether that practice was being followed at Robb Elementary on the day of the shooting. The shooting occurred after an awards ceremony, when relatives said they had come in and out of the building.

The Uvalde district's safety plan also described the use of the Raptor Visitor Management System, which scans visitor IDs and checks them against sex offender registries and lists of noncustodial parents.

At a news conference in Uvalde this week, Lt. Gov. Dan Patrick praised the district's security measures but suggested that limiting schools to a single entrance was an improvement worth considering.

Officials in Georgia and Virginia deployed additional officers to schools as a precaution, and Sen. Ted Cruz, R-Texas, suggested putting more armed police officers in schools. New York City, the nation's largest school district, said it would consider locking school doors after students arrive for the day. Los Angeles said it would reduce entry points for schools.

But Khubchandani questioned whether any of these measures would stop a next gunman.

"It's like medication for heart attacks while continuing to eat bad instead of eating healthy," he said. "You prevent this from happening or you don't."

Eileen Sullivan, Shaila Dewan and J. David Goodman contributed reporting.