Yeah that is a problem that vexed a lot of railroads around the world, whether it was narrow to standard gauge in the US (post standardization), the various gauges in the pre standards days, or in Europe where for example Russia deliberately used a different gauge to try and thwart invaders using their rail network all that easily......has been handled a variety of ways, offloading the cargo from one train to another at an interchange point, literally pulling the freight cars off their trucks onto the trucks of the new railroad and a new engine taking it on. There have been attempts in the past if I remember correctly, to build engines and freight cars that could adjust themselves (one method used a guardrail.main rail that slid in/out to reset the wheel set on each side), but they didn't work from what i know.