The endearing animated comedy “Ron’s Gone Wrong” (20th Century) gets a lot of things right.

Principal among these is a lesson about the true nature of friendship. That and the film’s other positive messages are conveyed, moreover, via a lively story that might occasionally scare little ones but is otherwise acceptable for all.

Barney Pudowski (voice of Jack Dylan Grazer), a kindhearted but socially isolated middle schooler, yearns for a “B*Bot,” the robot toy that has become a status symbol among his classmates.

By the time his widowed dad, Graham (voice of Ed Helms), a cash-strapped novelty salesman, and his Bulgarian immigrant grandmother Donka (voice of Olivia Colman) figure out what Barney wants, however, it’s too late for them to purchase a B*Bot for him as a birthday gift through normal channels. So they resort to buying one that literally fell off a truck.

Quickly discovering that his new companion, Ron (voice of Zach Galifianakis), is damaged goods, Barney spurns him. But quirky Ron proves to have winning ways and Barney gradually comes to appreciate the affection and sunny good nature underlying his eccentricities and technical shortcomings.

Co-directors Sarah Smith, Jean-Philippe Vine and Octavio E. Rodriguez, working from a script Smith co-wrote with Peter Baynham, wreak entertaining chaos along the way to a touching conclusion that showcases altruistic goodness. They also send warnings about the need to resist both peer pressure and mindless consumerism.

Additionally, Barney’s eventual bond with Ron provides the movie with an implicitly pro-life theme since it invites viewers to look below the surface and not reject those whose apparent limitations may mask deeper qualities and abilities. Ideally, the youngsters at whom “Ron’s Gone Wrong” is aimed will apply that insight to relationships in the real world.

As is almost inevitable, a bit of potty humor is added to the picture’s mostly wholesome mix. While this recurs across several scenes, it’s pretty tame stuff and so not a source of real concern. Likewise, a momentary lapse into less-than-polite language passes by swiftly and can easily be overlooked.

These brief detours aside, “Ron’s Gone Wrong” follows a steady course, guided by a reliable ethical compass. It’s a spirited, morally sound outing that parents and kids can enjoy together.

The film contains characters in peril, some mild scatological humor and a single slightly crass expression. The Catholic News Service classification is A-I — general patronage. The Motion Picture Association rating is PG — parental guidance suggested. Some material may not be suitable for children.

— John Mulderig