A Somerville man was charged with arson and attempted murder after he allegedly set fire to a Hillsborough house while eight people slept inside, law enforcement officials said.

Patrick Hammond, 34, of Somerville, started the fire outside his ex-girlfriend’s Starview Drive home around 12:40 a.m. Sunday, Somerset County Prosecutor Michael H. Robertson said. All of the residents, who ranged in age from 4 to 64 years old, were able to escape.

Hammond texted a photo of the burning home to a friend minutes after the fire was reported and ran away, police said.

Within an hour of responding to the scene, officers said they found Hammond less than a mile away. He started acting erratically when they took him to the Hillsborough Township Police Department, so they brought him to a nearby hospital for evaluation, Robertson said.

Hammond had previously threatened to set his ex-girlfriend’s truck on fire, Robertson said.

An online fundraiser for the family said two pet cats and fish died in the fire. Half the house and multiple cars have fire damage, according to Amy Chess, who said she is a friend of the family. A photo on the page shows a severely burned house with a back wall and portion of the roof destroyed.

The Red Cross responded with emergency assistance, the prosecutor said.

The preliminary investigation showed the fire was intentionally started near the back of the home, Robertson said.

Police asked those with information about the incident contact the Somerset County Prosecutor’s Office Major Crimes Unit at (908) 231-7100, or the Hillsborough Township Police Department at (908) 369-4323 or via the STOPit app.

Cassidy Grom may be reached at cgrom@njadvancemedia.com Follow her at @cassidygrom. Find NJ.com on Facebook. Have a tip? Tell us. nj.com/tips