Karen Gillan as Nebula and Don Cheadle as James Rhodes in “Avengers: Endgame.” (Disney/Marvel Studios/AP)
Ryan Wasserman is chair of the philosophy department at Western Washington University, and author of "Paradoxes of Time Travel."

In the newest Marvel blockbuster, “Avengers: Endgame,” our heroes embark on a desperate attempt to reverse the catastrophe of the previous installment, in which the series villain Thanos eliminated half of the life in the universe. It is not much of a spoiler, since roughly half the life in the universe has seen the film, to say that time travel features prominently.

Time travel — including its fictional depictions — is of interest to philosophers because (its physical possibility aside) it raises fascinating logical challenges. Consider, for example, the “grandfather paradox,” as scholars call it: If time travel were feasible, then you would be able to go back in time and kill your infant grandfather. But in that case, your grandfather would never grow up to sire your father, in which case you would never be born — in which case you could not go back and kill your grandfather. In other words, time travel seems to imply the contradiction that you both could and could not commit retro-grampatricide. For this reason, some philosophers conclude that time travel is logically impossible.

“Endgame” is noteworthy in that its characters explicitly discuss paradoxes of this kind. In one scene, the Hulk tells the other Avengers that they can’t use time travel to go back and kill baby Thanos, a solution that had immediately occurred to the group, because doing so would render impossible the “future” in which they are having the conversation. (After all, the entire reason they are debating what to do is that Thanos was not killed as a baby!) The Hulk even argues that such conundrums render many classic time-travel movies, including “Back to the Future,” nonsense. (The screenwriters said this week they added the Hulk speech after early test audiences were confused by the movie’s theories of time travel.)

But the time-travel plot of “Endgame” nonetheless includes a number of confusions that threaten the coherence of its story — although thinking through these missteps can itself be a rewarding exercise.

The Hulk’s way of thinking about time travel presumes that time operates like a single pathway. But another possibility is that time travel creates new “branches” of time, in which alternative histories can unfold. For example, if a time-hopping assassin went back to kill his grandfather, we could imagine that an alternative timeline is created in which the grandfather is, in fact, killed. This would not generate any contradiction, since the grandfather would still be alive (and go on to have grandchildren) on the original branch. By this way of thinking, if the Avengers went back and killed baby Thanos, that would not be illogical, since Thanos would still commit his crimes (and time travel would still be developed in response) on the original branch.

Of course, you might wonder whether killing baby Thanos would be worth the effort in this scenario, since it would not prevent his atrocities on the original timeline.

Branches do come up at several points in “Endgame”: In a conversation with the Hulk, a seer called “the Ancient One” provides a visual representation of a single timeline dividing and suggests that removing an Infinity Stone from one moment in time will create an alternative reality; Tony Stark, likewise, alludes to multiple branches when he mentions the (real) Oxford physicist David Deutsch, who is known for his theories about “multiverses,” a scientifically respectable version of the branching-timeline view. But as the Hulk’s lecture suggests — and comments by the screenwriters seem to confirm — all of the events depicted in the film take place on the original, “main” branch of time. So, if there are in fact other universes — as there were in last year’s “Spider-Man: Into the Spiderverse” — we’ll have to wait for a future movie to find out what’s happening in them.

Another response to problems such as the grandfather paradox is to stick to a single, unalterable timeline — yet insist that travelers always act in accordance with the actual historical facts. You might go back in time to kill your grandfather, but your efforts would invariably be thwarted (guns will jam, a banana peel will be slipped on, etc., etc.). This does not necessarily mean that you can’t kill grandfather, but it certainly means that you won’t. One way or another, history will have to turn out the way that we know it eventually does (from the vantage of the future/present).

The Avengers in “Endgame” take care not to alter the past: The plot involves going back in time from the year 2023, retrieving the all-powerful Infinity Stones from various places, returning to 2023 to use them as a weapon, and then putting them back into their original places, in the past — so that they can play their appointed roles in the earlier Marvel movies.

A plot line involving Captain America appears to violate the Hulk’s (and some philosopher’s) “don’t change the past” rule — but only at first glance. At the end of the movie, we learn that Cap stays in the past after completing his mission, to live a normal life totally unlike what we know about the arc of his superhero career. However, this is perfectly compatible with everything in the earlier Marvel movies; we just have to imagine that there were two Captain Americas running around throughout the course of those films -- a young Cap battling Loki, Ultron and so on, and an old Cap enjoying his retirement. This is a bit odd (one thing in two places at the same time?), but it is not logically contradictory.

In short, most of the movie appears to follow its own rules for time travel — at least until the final act.

In the climactic battle at Avengers headquarters in 2023, Thanos’s blue-hued daughter Nebula confronts — and eventually kills — an earlier version of herself who had traveled forward in time, from 2014. But if she kills that version of herself, then that version cannot return to 2014, in which case she cannot do other things we know that she did from earlier films -- make peace with her sister, join up with the Guardians of the Galaxy or fight alongside the Avengers. Even more basically, if the “later” Nebula kills the “earlier” Nebula, there can be no “later” Nebula. This is an instance of the “retro-suicide paradox,” a variation on the traditional grandfather case.

A second and more significant issue concerns the fate of Thanos. Like Nebula, Thanos is supposed to have traveled to Avengers headquarters from 2014 — from a point before his actions in “Infinity War.” But then we have a problem. If Thanos is killed in 2023, then he, too, will not return to 2014, in which case he will not collect all the infinity stones and wipe out half the galaxy. But Thanos did do all those things. That’s the entire point of the film. So, again, a contradiction.

Of course, none of this is to say that “Endgame” is a bad movie, although it might have been a better one if it had avoided the very paradoxes that the screenplay draws such careful attention to. But there’s nothing we can do about that — not, at least, if the Hulk has the right view of time travel.