TheHelpfulHelper
✅ Conversions of types between two libraries
So I have two libraries (A and B) which both have their own Vector3 structs and in my project I want to pass them back and forth, because the libraries offer different functionality that uses the Vector3s.
Do I have to create an intermediary representation that implements implicit conversions in both directions or is there a better way?
A round-trip would look like this currently:
LibA.Vector3 > MyCode.Vector3 > LibB.Vector3 > MyCode.Vector3 > LibA.Vector3
Not just does this create a lot of boiler-platey code if I have to do it for all of the other Mathematical structs (Vector2, Vector4, Quaternion, Matrix3x3, Matrix4x4 etc.) but it also seems kinda wasteful, if it actually has to allocate memory for each cast which is pretty much immediately discarded again...
23 replies