One of the most appealing aspects of a career in academic science and engineering is the freedom to choose your area of research. This freedom is extremely rare in an industrial setting, and becoming more so all the time. Taking myself as an example, I was hired as an experimental condensed matter physicist, presumably because my department felt that this was a fruitful area in which they would like to expand and in which they had teaching needs. During the application and interview process, I had to submit a "research plan" document, meant to give the department a sense of what I planned to do. However, as long as I was able to produce good science and bring in sufficient funding to finance that research, the department really had no say-so at all about what I did - no one read my proposals before they went out the door (unless I wanted proposal-writing advice), no one told me what to do scientifically. You would be very hard-pressed to find an industrial setting with that much freedom.
So, how does a scientist or engineer with this much freedom determine what to do and how to allocate intellectual resources? I can only speak for myself, but it would be interesting to hear from others in the comments. I look for problems where (a) I think there are scientific questions that need to be answered, ideally tied to deeper issues that interest me; (b) my background, skill set, or point of view give me what I perceive to be either a competitive advantage or a unique angle on the problem; and (c) there is some credible path for funding. I suspect this is typical, with people weighting these factors variously. Certainly those who run giant "supergroups" in chemistry and materials science by necessity have more of a "That's where the money is" attitude; however, I don't personally know anyone who works in an area in which they have zero intellectual interest just because it's well funded. Getting resources is hard work, and you can't do it effectively if your heart's not in it.
A related question is, when and how do you shift topics? These days, it's increasingly rare to find a person in academic science who picks a narrow specialty and sits there for decades. Research problems actually get solved. Fields evolve. There are competing factors, though, particularly for experimentalists. Once you become invested in a given area (say scanned probe microscopy), this results in a lot of inertia - new tools are expensive and hard to get. It can also be difficult to get into the mainstream of a new topic from the outside, in terms of grants and papers. Jumping on the latest bandwagon is not necessarily the best path to success. On the other hand, remaining in a small niche isn't healthy. All of these are "first-world problems", of course - for someone in research, it's far better to be wrestling with these challenges than the alternative.