Cheapest and safest way to clean MTB drivetrain? I've got a CUBE Attention MTB which has been serving me well, but out of a lack of knowledge I never bothered to degrease the chain before relubing it, so over time there has been a build up of gunk and hardened material that I haven't really noticed because my whole drivetrain is black.

I've heard people telling me to degrease it with WD-40 and then simply relube it but this doesn't seem to be a good idea. What are your personal tips and tricks regarding this?
Cyclingtips has a nice deep dive into this, albeit it appears more focused on road bikes. The author’s take is that you can simply wipe the chain off after every ride without degreasing, then re-lubricate occasionally. The author believes that if you just use degreased on a rag, then all you get degreased mixed in with the lubricant, so your chain is actually less lubricated.

MTB and gravel bikes will get more dirt intrusion into the rollers, that road bikes, but even road bikes will get some. That dirt forms a grinding paste which increases chain wear. Thus, many people will benefit from getting an on-bike chain cleaner. This houses brushes and a lubricant reservoir (NB: dilutes dish soap will suffice). You can run your chain through it, and it will get it cleaner that simply wiping it off. You would then let the chain dry, then re-lube.

Naturally, there are more thorough methods that are detailed in the article. You should not allow yourself to be intimidated by them. Simple methods are enough for almost all riders. But yes, you could remove the chain, soak it in solvent (perhaps in an ultrasonic cleaner), then lubricate it or dip it in wax. But you do not have to do this.