In UBW, Gilgamesh kills Archer. How come he's still around at the ending when he helps Shirou?
Turns out, Gilgamesh doesn't actually kill Archer. Yes, he skewers him with multiple weapons, but that apparently isn't enough to off him. When you see Archer disappear after being skewered, that's him changing to spirit form, rather than him dying and dematerializing altogether.
Kind of an unsatisfying explanation, but it is what it is.