There is a way to ensure this and receive a good ending with everyone present. If you go into the "more options" part of the main menu you can take a look at the scene flowcharts to find specifics on how to achieve this but as a general rule for characters to accompany you to the end you'll need a certain level of affection with them.