I cant find the source right now but when Shyamalan wrote the Sixth Sense, it was a complete script on about the fifth draft before he even _thought_ of the twist. And I think thats why its such a great movie. Its like a twist that gives you a whole new movie on top of the perfectly good one you've already seen. And the twist is not just a gimmick, it has emotional depth.
edit: I first saw the sixth sense in perfect conditions - a pirated VCD from Malaysia before any publicity for it had happened in the UK, so had no idea what I was getting myself into other than it had Bruce Willis in it. Absolutely blew me away.
edit: found the source:
According to an interview in Scenario magazine (Volume 5, Number 4), Shyamalan had written five drafts of the screenplay before an idea came to him that transformed it into something totally new, leading to a landmark film with powerful performances from the film’s stars. It happened in the sixth draft.
https://www.stevendeeble.com/2016/05/31/evolution-of-a-scree...