SPOILERS for Glass ahead.
M. Night Shyamalan says he always had an "operatic" ending in mind for Glass, even back when he was making Unbreakable. Glass marks the long-awaited conclusion to Shyamalan's Eastrail 177 trilogy, which began with Unbreakable in 2000 and unexpectedly continued with Split in 2017. All three films takes place in a universe where superheroes not only exist, but have walked among us for thousands of years and inspired our myths throughout history, comic books included. Bruce Willis played one such metahuman in Unbreakable, in the form of David Dunn: an ordinary security guard who, after becoming the lone survivor of a horrific train crash, discovers he has super-human strength and durability.
Split would later introduce another metahuman in Kevin Wendell Crumb (James McAvoy), a man who dissociative identity disorder who - after being abused by his mother as a child - develops twenty-three unique personalities and, eventually, a twentieth-fourth one that's bullet-proof, can climb on walls, and subsists on human flesh (known as The Beast). David and Kevin are linked by Elijah Price (Samuel L. Jackson), a man with super-intelligence and brittle bones who was responsible for causing the Eastrail Train 177 disaster, which led to David discovering the truth about himself and Kevin's father being killed (in turn, leaving Kevin to be abused by his mom and develop his many personalities). Glass ends with all three men being killed, which is apparently what Shyamalan had in mind since the beginning of his trilogy.
In a recent interview, EW asked Shyamalan if he always had this kind of ending in mind to his Eastrail 177 trilogy. Here's what the filmmaker had to say:
“I did. I always thought it was a little bit of like an opera, even when I was starting on Unbreakable. I thought this was a very operatic end to it all [with] people screaming and all of these kinds of implications. It was about implications more than anything. I’m a big fan of One Flew Over the Cuckoo’s Nest as you can probably tell. The format of that movie just blew me away when I saw it. The idea that the journey of the main character gets fulfilled by another character is a very powerful idea.”
Shyamalan may've had a rough idea of how Glass would end since he made Unbreakable, but his larger plan clearly evolved and changed over the last twenty years. Tonally, Glass has more in common with Split's blend of horror and comedy than Unbreakable's brooding atmospheric style and melds the two approaches with (arguably) mixed results. There's also the matter of the Clover organization, which is introduced during Glass' third act as a shadowy group/society that's been keeping the existence of "superheroes" secret for a very long time and is ultimately responsible for killing David and Kevin (after The Beast mortally injures Elijah for causing the Eastrail 177 train crash and "creating" him). While there's a fair debate to be had about whether the Clover twist was carefully set up in Glass or comes out of left-field, there's no real set-up for the organization in either Unbreakable or Split.
Jackson's claimed that Glass' original ending changed in other ways too, in order to better reflect society and the world at large today. It's possible this is a reference to how Glass concludes with Elijah's mom (Charlayne Woodard), David's son Joseph (Spencer Treat Clark), and Casey Cooke (Anya Taylor-Joy) from Split leaking surveillance footage of David and Kevin using their super-powers to the world, after Elijah managed to sneak it online without the Clover society's knowledge. It's highly doubtful Shymalan had that part of the film planned out when he made Unbreakable, given how much the internet has changed in the past nineteen years. Regardless, he got the "operatic" ending he always wanted with Glass, and people will no doubt continue to debate its merits for years to come.