Like Julia has sciml youtube lectures showing the guy doing all kinds of optimization to improve the libraries for HPC but he had a specific goal why he's doing that, he runs a startup pumas.ai
For me it was basic competency at Y subject I was very interested as first goal, find a mentor and work beside them for Y subject (second goal) finally become an expert at Y to freelance and I wrote all that down years ago because I too was just aimless and dabbling then giving up.
To find a mentor I had to impress them first to make it worth their time so that was motivating to slog through all the fundamentals in the beginning. Normally I would've given up here because who on earth wants to deep dive logical relations unless there's a good reason. Working was then a motivator too because I was given tasks to figure out with deadlines so there was urgency and focus so the person I chose as a mentor would actually keep teaching me.
Before that I would take interesting thing, that thing goes into the weeds to teach foundations and I gave up bored chasing new thing and repeat with no direction at all.