Before Mark Wahlberg ever attempted to test his mettle vis-a-vis giant metamorphosizing robots from outer space — before he befriended a heroic battle-bot named Optimus Prime on screen — the actor prepared for his latest part with an unlikely foil: a talking teddy bear with an outsize taste for prostitutes and cocaine.

Which is to say that before Wahlberg signed on to appear in Paramount Pictures’ mega-budget sci-fi thriller “Transformers: Age of Extinction,” he got a first taste of acting opposite computer-generated imagery in a certain raunch-comedy that became 2012’s surprise breakout hit.

“‘Ted’ was definitely a good warm-up,” Wahlberg said of the movie in which he plays a Boston bro who co-habitates with his hard-swearing, magically alive plush toy. “With ‘Ted,’ it was a more intimate setting. But this movie is much bigger and more intense. You’ve got eight Autobots talking to you at the same time. There’s nothing but a pole or a stick really there. You’ve got to believe and totally commit. The most difficult part of acting is when you look ridiculous and have to confront the risk of looking foolish. You’ve got to be on the whole time. You can’t phone it in.”

“Age of Extinction,” which hits theaters June 27, arrives as a kind of reboot for the franchise, which has grossed $2.7 billion worldwide, and is the first entry in an intended new trilogy of “Transformers” films. Wahlberg takes over as protagonist from Shia LaBeouf, who departed as the series’ primary human foil, Sam Witwicky, after “Transformers: Dark of the Moon” in 2011.

Never mind that Wahlberg — as a down-on-his-luck auto mechanic who discovers a dilapidated truck that turns out to be none other than the leader of the good-guy Transformers, the Autobots — prefers to consider the movie on its own merits rather than as fitting into a global juggernaut (which also encompasses a cartoon series, Happy Meal toys and amusement park rides).

“Some people think of this as a sequel,” he said. “We thought of it more as a stand-alone thing. I’ve never done a sequel.”

Chock-a-block with the kind of signature bombast for which director Michael Bay is known — armadas of black Escalades, swarming SEAL teams, enormous explosions and menacing displays of high-tech hardware adding to its $165-million budget — the new film departs from the prescribed “Transformers” universe to present a world in which Autobots are no longer viewed as friends of man. It’s a post-Witwicky era when the Earth’s populace is unclear about who their extraterrestrial robot enemies are.

For nearly six months, the production hopped across America, filming in locations including Chicago, Detroit, Texas and Utah before moving to China and shooting in the teeming slums of Hong Kong. The only filming hiccup came months after principal photography had wrapped. Wahlberg had shed 60 pounds from his 197-pound frame to portray a literature professor with a gambling addiction for the 2015 remake of James Caan’s 1974 “The Gambler.”

“I had to come back for some pick-up shots,” Wahlberg recalled. “So when Bay saw me, he freaked. He was used to seeing me on the healthier side. But here I am skinny with long, stringy hair. He was like, ‘You can’t look like that!’”

In the end, Bay managed to film Wahlberg in a way that obscured his, ahem, transformation.