Different brands and models of shower valves require different wall-depth installation. You should always follow the installation instructions.
Some Shower Mixer valves come with a temporary plastic or cardboard "plate" that illustrates the location of the finished wall surface in relation to the valve-body installation depth. If you do not have that "template" anymore, you can often estimate depth by assembling the trim to the valve and measuring from where the wall surface would be to the mounting holes. You need to locate the supply piping according to final installation depth of the valve, not the other way 'round (not an issue with flexible supply tube).
Except for special application products, they are made to fit a standard wood-frame wall but may not allow the use of 2 x 4 lumber as a mounting support; in fact, some recommend use of a manufacturer-specific mounting strap/stringer.
Example of depth mounting instructions for a random Mixing valve model:
Because valves generally only install at one level, most valves have a threaded portion that brings the knurled portion in and out about a half an inch. If you valve doesn't have this, you will likely have to break up the tile in the front and re-install the valve unit.