Whilst the spacing between cogs should be the same the position of the cassette on the freehub may not be the same so the derailleur may need adjustment. Does the second set of wheels have the same hub as the original?
I have a Hope hub with XD freehub and SRAM 11 Speed cassette on one bike and Specialized (Formula?) hub with Shimano type freehub and SRAM 11 Speed cassette on the other. I also have an old Formula hub (but different to the Specialized), XD freehub and SRAM cassette which I use to replace either wheel for cleaning and maintenance. Gears work really well whatever's on either bike - if that's of any help.
The World's largest electric mountain bike community.