In How I Met Your Mother, Ted tells his kids the lengthy story of his life during his twenties and thirties. His "official" intention is to tell them, as per the title, how he met their mother.
In the finale however we find out that he really did this (knowingly or not) to ask permission to date their aunt Robin. His wife has been dead for six years and he apparently never really got over Robin, who divorced Barney after three years of marriage.
The ending came as a surprise to many fans and produced some major outrage (*salutes*). It especially seems a bit strange that they spent quite some time on Ted and Robin realizing that they are not a good fit and building up Barney's and Robin's wedding for a whole season, just to rip it all apart within a few minutes.
Originally the show was only meant to run for two or three seasons and was extended again and again due to the great success. This raises the question:
Did the producers have this ending in mind from the get-go?
Did they already know how it would end when they started the show? Did they maybe change the overall story in light of the much longer run-time and the development of characters, or did they make a plan and stick to it?
The fact that all footage of Ted's children had to be recorded during the start of the show, because the actors would have gotten too old over time, seems to imply that the ending was already decided and partially shot during Season 1 or 2.
Is there any statement from the producers about this? Was the footage really recorded in advance? Was it maybe somehow produced through CGI/re-dubbed?
It seems very odd to me that they would stick to an ending they wrote years ago and not take into account the development the characters made onscreen. (e.g. the changed relationship between Ted and Robin, or the emotional development Barney went through)