Take heed: There are at least two acutely sad moments involving Robin Williams’ Teddy Roosevelt in the latest “Night at the Museum.” The movie, subtitled “Secret of the Tomb,” is imbued with the unshakable inevitability that even though we’re still having fun, it’s time to move on—a narrative made only more poignant by Williams’s sudden and shocking death earlier this year.

It’s hard not to concentrate on his every movement and word or to get antsy when he’s in the midst of a bit and the camera cuts away to a monkey peeing on something, leaving us straining to hear Williams’ voice. And yet, as silly a role and movie as this is, it also manages to live up to the (unfair) responsibility of being a comedy legend’s last role. Director Shawn Levy and his team strike the right balance, without overwhelming the story with melancholy.

Beyond Williams, “Night at the Museum: Secret of the Tomb” is a lively romp with the over-the-top historical figures that audiences have come to enjoy over the years that, in spite of the dead zones, elicits more than a few bawdy laughs throughout its swift runtime.

The latest installment delves (not too deeply) into the mythology of the ancient tablet that brings the museum fixtures to life. When the golden treasure starts to corrode, things go haywire, leading to a particularly disastrous fundraising event as all the characters revert to their true, violent selves and, inexplicably, Teddy Roosevelt starts quoting Winston Churchill and John F. Kennedy.

The specifics are a little murky, but what is clear is the magic that brings inanimate objects to life is in danger of disappearing forever (a franchise’s greatest fear!). Their only hope is to go to the British Museum to ask Ahkmenrah’s (Rami Malek) parents for help.

As in the previous movies, “Secret of the Tomb” buckles under the weight of its phenomenally talented cast who just aren’t given enough to do, making it feel more like a movie of cameos rather than a true ensemble work. That said, Owen Wilson and Steve Coogan, once again, provide many of the film’s laughs as the pint-sized Jedediah and Octavius—as does Ricky Gervais as the wimpy museum director.

In London, we’re introduced to a few new characters, including Lancelot (Dan Stevens) and a new nighttime security guard named Tilly (Rebel Wilson). There’s also a terrific “Camelot” related cameo later on in the film that we won’t spoil here.

But the weaker spots are hard to ignore. The movie spends too much time on a few plots and jokes that never hit. One involves Larry’s Neanderthal doppelgänger (both are played by Ben Stiller) who should be a welcome relief, finally allowing Stiller to escape the unexciting Larry and bite into something broadly comedic. Instead, it’s flat and redundant.

Another focuses on Larry and his teenage son Nicky (Skyler Gisondo, replacing the previous films’ Jake Cherry), who really just wants to skip college and DJ in Ibiza. Why we even need a family story here is beyond comprehension. There’s nothing duller than watching a father with a furrowed brow try to convince his rebellious offspring that college is necessary. It’s too bad: Left to his own devices, Gisondo has a handful of truly funny moments with Lancelot.

In the end, “Secret of the Tomb” certainly wasn’t necessary, but its earnest goofiness is hard to resist. The bittersweet goodbye to Williams just makes it all the more worthwhile.