I keep hearing that if you develop a game for pc or android you need to optimize it for every single different hardware. how much of that is true? and is there a thing that does that for you?

Unity works like shit on Android phones if you load too much shaders into it.These days, as long as you're using a pre-made engine like Unity or UE or whatever, it'll already be "mostly" optimized to run on most systems that can run that engine.
i have noticed that unity games run like shit, but i never had any problems with unrealUnity works like shit on Android phones if you load too much shaders into it.
UE even worse if you don't have atleast Mali-Txxx or Tegra card inside.
You don't have to really optimize it, just make it slightly run better. It's impossible to do that for every single phone out there since they vary from MSM-Snapdragon processors.