I used to compose simple piano solos just for the fun of it, because I enjoyed doing it. More recently, I've pushed myself to start composing more elaborate, complex or intricate pieces designed for video games, so that covers the idea of your work being "useful" which has been brought up several times. For me, the biggest motivation is the satisfaction of not only completing a song and having it be used for something, but also being able to then listen to and/or play it whenever I feel like it.
It also feels rewarding to make something and then get positive or constructive comments from friends, family, and others, and that encourages me to continue making bigger and better musical creations.