I recently just went through the process of stripping out my project code from the speckle-unity repo and exporting the speckle-unity project as a one off unity package that I could import into my other unity project. All is well in good with that but it made me realize that most of that hassle I went through was separating out the
ISpeckleConverter class for unity and how that get’s integrated within the
SpeckleManagerConnectorThing. It would be helpful to consider how a client, like unity, might deal with handling kits and converters (mainly converters).
I thought it would be good to have a lil’ convo around this process. Here are some of things I think a solution would need to address.
Serializing the Converter in Unity
Right now in order for a converter to work in Unity a user needs to build out that converter, reference it in the
ConnectorUnity namespace, and then modify the
Receiver class to use that converter. What would be ideal is creating a simple object that any receiver or sender could have access to and rely on that for converting (just like it does in any other connector) without the need of hardcoding it. But we would need to create a unity friendly object that it could rely on for storing and accessing the different converters. For example,
ConverterUnity is the current Object converter that is just a simple
object that can be instanced in unity during runtime or editor, but it won’t be serialized since unity doesn’t chill like that with
objects. We could attach
MonoBehaviour or a
ScritableObject class to it, and then unity would be a-okay with serializing that.
I did a pass at addressing this issue by creating an abstract object that a converter could inherit from and then adding those to a container scriptable object. Here is the UnityConverter with that class implemented. The
kit and converter object really just a way for the speckle manager to know what converter is should utilize.
Here is an epic gif of the manager with reference to those converters (flexing that logo).
I’m sure there is a more elegant solution that could be built out with reflections, robots, maybe even a skylight, but I’m more of a peon type of developer.
Packaging Converters and Objects
Currently speckle converters and objects need to be added directly to the project. I’m sure on the unity-connector roadmap there some plan to migrate the project into the package manager, but I think it would be helpful to have objects and their converters be separated too. I’ve been using OpenUPM to package my
viewobjs and I plan on doing the same with the unity-converter. However, my unity converter piggy backs off the speckle one (
ConverterUnity, no need to repeat mesh building code…) so I can’t separate that out from the main project repo. This structure would be a bit more relatable to the current structure of other connectors too.
anndd we out