When I started, I just couldn't see myself doing the same thing for the rest of my life and I branched out. I took opportunities that presented itself and the ones where I was thrown into (thank you mentors). I did try to specialize in engineering but I went from embedded systems to GUI to front-end to back-end to data (mining/analysis/visualization) to systems design to (developer) operations then ML and technical management. I just can't help but be attracted to the next thing but I don't stick around long enough to be absorbed by it.
I usually start the 'next' thing as a side project or side gig. If it becomes interesting enough I change my main role to it. In a way I've become a specialist at being a generalist.
Fear of the unknown doesn't frighten me, it excites me. Somehow I've come to love chaos and making sense of it. Few people and companies bet on this behaviour of mine and we both walked away with satisfaction and wealth. But life as a generalist hasn't been easy. I've had to deal with imposter syndrome often. Always ended up learning on the job.
It wasn't just jobs/career though... I find myself relocating to new country or continent once every two years. Financially it's a nightmare but its a price I'm willing to pay.