Unity Sender Issue

Hi everyone,

Hope you’re all doing well,
I’m trying to make a loop between grasshopper and Unity, I can stream meshes from GH to unity and have done all the sorting etc. now I need to send the meshes back from Unity to GH in new Positions, but I couldn’t figure out how exactly the SpeckleUnityUpdate and SpeckleUnitySender work. They should probably be controlled by SpeckleUnityManager (?) but how can I assign the sender component?


Hey @ArianSDF,

I’m not sure if a single Speckle stream can be received and sent at the same time (I don’t know as much about speckle as I should, I just help develop the Unity plugin) but here’s what I do know:

There was a sending API written by the original author @cwm but it didn’t perform well at larger scales and was disabled until a more scalable solution could be found. You can downgrade SpeckleUnity to version 0.2.1 in the package manager or clone this version of the source code: GitHub - speckleworks/SpeckleUnity at c86f55d8701facc0014a5fdbf61d94029bedf4f8

This version contains an older workflow where there were prefabs set up for managing, sending and receiving separately as opposed to the new workflow featured in the documentation. There’s even example scenes for sending speckle streams.

The big BUT in all of this is that Chris only got sending to work for points (positions) and single number values. Not whole meshes. Also, since sending and receiving were coded to work separately, you’ll need to handle copying the received objects over to the sender to then be manipulated and then sent back up. So you’ll need to do a fair bit of leg work anyway.

I’m developing the unity package to be aiming for feature parity with the web viewer (readonly) first since it’s much more straight forward, gets the most features into the package and can be considered production ready much sooner as well (the package is still very much in preview).

In the off chance you do develop you’re own solution please make a fork of the repo and share it with us!

Hello @ArianSDF! @pablothedolphin got it right, sending and receiving from streams at the same time is a no go. As a rule of thumb, speckle’s stream’s should be considered as one-directional data flows. You can, though, make loops: just send the updated/modified data from one stream through another one which can be received in grasshopper.

It would look something like:

Gh ---- [ stream A] ----> Unity
^                          V
|                          |
|                  [changes happen]
|                          |
|                          V
. --<-[ stream B] ----<--- .

As an aside, i probably spent the same amount of time on the text diagram above as I would’ve in illustrator…

1 Like

The old version that @pablothedolphin is talking about is really not even a ‘version’. It was the bare minimum that I needed for a specific project I was working on, and I put it on github in the hopes that someone with more skills than me might develop something actually usable (Thanks Jak!!)

That being said, it shouldn’t be too difficult to add the rough ability to send meshes to the old version… I didn’t write it because I didn’t need it at the time, but it would mostly just need a conversion method from a unity mesh to a speckle mesh I think. The harder part might be just using the old version in the first place :slight_smile:

WOW ! Thanks everybody for fast responses !

sorry if I wasn’t clear. what I need is exactly what @dimitrie shows.
I just need to simulate the physics in Unity send the result back in GH. It would be amazing if it could send the result in every couple of seconds and if not, there won’t be a problem. I can just set a button for send Class.
On the other hand if I could even just send vertices. Then I can rebuild the meshes with new coordination in GH. It would however make the process heavy and slow and won’t be optimal.

If you are not deforming the meshes in Unity, it would probably be faster to just send the transforms rather than all the vertices of each mesh. It would require a little more set up on the GH side of things. And it would require writing a converter from Unity transform to a Speckle plane (which actually I think I did write at one point, but may not have made it into the repo)

Again, I think the bigger challenge would just be getting the old version to work with your set up… If you are looking for a very rough one-off proof-of-concept kind of thing, you might be able to make it work. If you decide to go that route, see if you can get it to send back anything to start (and then I can maybe help get it sending meshes or planes back)

If you are looking for something more sustainable though, you’d probably have to build sending functionality yourself off of the current package.