It's more complicated than that. Technically, you're right, if the game entirely relies on steamworks for networking you can only play with people on steam. A lot of indies/AA actually just did that for a while because they just connected players P2P (so, no dedicated servers, which would necessarily be "outside" of steam's ecosystem) and crossplay was too complicated, so there are a lot of multiplayer games out there that you literally can't play crossplatform, at least in a user friendly way (shadow warrior 2 comes to mind, where you can actually connect the GOG version to the Steam version by entering a console command and knowing the other guy's IP).
Big publishers like Ubisoft definitely had the developers and the money to roll out their own crossplay architecture and code very early though, and they absolutely did. Basically, if the game has dedicated servers it most likely has crossplatform.
Nowadays a lot of UE games just rely on Epic Online Services for crossplay. I think you can actually use it with non-UE games too but there might be licensing shenanigans involved.