How to send from Unity - Want to see what is in SpeckleProperties

Greetings. I have been using Speckle in connection to Revit for BIM implementation. So far it has been great for receiving models from Revit into Unity.

Now I am interested in sending it out of Unity. So how do I actually do this? I checked the docs section here: #Sending but I am not very experienced in programming so I did not understand much.

Reading the #Metadata section of the docs it says the model information is stored in the SpeckleProperties script, which is indeed added to each imported game object in Unity. But how do I see what is inside of it for each game object?

My reason for looking into this is: When you export a Revit model for example as IFC schema, each model entity gets a GUID (Global Unique Identifier) which can be used across different applications to make a reference to that exact same model entity.

I want to better understand if this GUID is somehow imported and preserved when receiving the model in Unity, and also if it is preserved when sending the model out of Unity. Thanks!

Hi @FilipeFinco,

Our current version of the connector doesn’t provide a convenient editor script for sending like we do for receiving. So to send geometry, you will need to write some code that uses the Sender class. This should offer you the functionality you need. You only need to specify the stream id, and a list of GameObjects to send.
The other properties are optional, and used if you want error handling/to be notified when the send operation is complete.

For a usage example, you can download our sample “Speckle Playground” project by cloning/downloading the unity repo. Checkout the InteractionLogic class.

This process may not be super straightforward, especially if you are new to unity, so please let me know if you are having any issues.


SpeckleProperties are a component that are attached to every GameObject created.
This should contain all the bim/custom properties you see when inspecting objects in the Speckle viewer.

Currently, the only way to access these properties, is from code.

SpeckleProperties props = myGameObject.GetComponent<SpeckleProperties>();

// props.Data is a IDictionary<string, object>

// you can check for a property like this:
if(Data.ContainsKey("area")
   && Data["area"] is int area)
{
    Debug.Log(area);
}

//And Add a property like this
Data.Add("area", 250);

A useful troubleshooting tip, is to breakpoint the keys to see what’s available for your objects.
I’m not 100% sure about GUIDs from revit, but if they appear in our Web viewer, they are accessible from within Unity.


In future, we were thinking that it might be nice to expose these properties to the inspector, and allow users to view/edit properties through the editor. But currently, the data is only accessible through code.

1 Like

Thank you very much for the reply! I will look into how to access the info on SpeckleProperties.

So I am trying to write a script that when attached to a Speckle Imported game object is able to access the SpeckleProperties component and return let’s say the value of the GlobalId. (I assume it would be the value associated with a key named “GlobalId” of the Data IDictionary, as you mentioned). See the images to see what property I am talking about:

GlobalId property of the IFC file:

GlobalId property imported to Speckle:

I am very new to C# so I am kinda messing with stuff I don’t fully comprehend here, but would something like this be the way to go?

I get some erros saying that the “Data” name does not exist in this context and that I am using unassigned local variable.

Would some script like this be the way to go to access this sort of properties within Unity?

Ah, sorry, there was a small mistake in the code sample I sent.
You should use props.Data not just Data.

Other than that, your code looks fine to me!

1 Like

Ok thank you. I still can’t get the if (props.Data.ContainsKey("KeyName")) to return true. I tried keys I know exist as I can see them in Speckle, like “id”, “Tag” or “Name” but it seems that the if never comes true. Maybe I am missing something still?

Ok, as a debug step, you could try printing all keys to the console.

Debug.log("printing keys:")
foreach(string key in props.Data.Keys)
{
    Debug.log(key)
}

Or if you are familiar with the debugger, you could try breakpointing the keys like I showed in a previous screenshot.

Also, the Id and speckle_type props are ignored, and won’t show up. but all other props should!


If you can’t get this to work, then I’d be happy to organise a quick call sometime this week.

Thank you! Using the foreach on the keys allowed me to see what was actually in there, and then using another Debug.Log I managed to get the value of some of the props, for example “elementId”.

When using my script on objects imported from Revit>Speckle>Unity it seems I can access most of the properties.

When I tried doing the same with Objects uploaded from IFC directly to Speckle via the import file option (IFC>Speckle>Unity) it seems some properties are missing, despite these properties showing up online in speckle. Most importantly in my case the “GlobalId” property is also missing.

I assume the Data dictionary in SpeckleProperties for the game objects originating from IFCs ends up getting generated differently which then causes some properties to not be present?

I would be very happy to have a quick call about this next week! It will be probably very helpful for me! How can we arrange this? Thanks in advance!

1 Like

Glad that you’ve been able to make some progress.

If the properties appear in the viewer, then they should be accessible from Unity, but I don’t think I’ve ever tested IFC → Unity, so there could be a bug somewhere :sweat_smile:

I’ll do some investigation, It might be useful for you to add me (jedd@speckle[dot]systems) as a collaborator on that stream, so I can try receiving your IFC objects myself.


I’ll send you a direct message, and we can organise a time for a call.

1 Like

Hi All,

I’m running into a similar issue with Unity.

I have created some objects in Blender and assigned each object a value using custom properties. The objects flow into Speckle fine and I can see them in the web viewer and see the properties there too, listed as myFirstProp:

When I try to access them, I seem to need to go an extra level down to access them but I can only get to the properties level, I can’t get to myFirstProp. However I try to access them, the Unity IDE is always pulling an error and won’t compile.

Below is working code to access properties and the Console log…


How do I access myFirstProp?

I don’t really know C# so I’m sure (and hope) it is something simple to fix.

Thanks for any advice you can give. I’m new to Speckle (and pretty new to Unity) but it seems great so far apart from this small snag!

Hi @David_Hunter,
I think you were very close in your above screenshot.
Debug.log(props.Data["properties"]); prints out the type of your properties object; a Dictionary<string, object> (although it gets formatted a little differently)

Knowing this, all you need to do is cast (i.e. tell C# to expect this type).
There are a few ways you can do this, I generally recommend using the is operator, as it will check that our value is non-null, and the type we expected.

var props = instanceToCheck.GetComponent<SpeckleProperties>();

if(props.Data["properties"] is Dictionary<string, object> blenderProperties)
{
    if(blenderProperties["myFirstProp"] is float myFirstProp)
    {
        Debug.log(myFirstProp);
    }
}

If you are new to C#, you might find it interesting to know there are a few other ways to cast types, depending on what you want to happen if the cast fails (i.e. your property either was null, or wasn’t a dictionary)

Using the explicit cast operator, if the cast fails, it will simply throw an InvalidCastException.

var props = instanceToCheck.GetComponent<SpeckleProperties>();

var blenderProperties = (Dictionary<string, object>)props.Data["properties"];

var myFirstProp = (float)blenderProperties["myFirstProp"];
Debug.log(myFirstProp);

And for the sake of completeness, You can also use the as keyword, which will simply return null if the value is not the specified type.


var props = instanceToCheck.GetComponent<SpeckleProperties>();

var blenderProperties = props.Data["properties"] as Dictionary<string, object>;

//note... blenderProperties might be null here, so this line below may fail
var myFirstProp = blenderProperties["myFirstProp"] as float;
Debug.log(myFirstProp);

In general, I prefer the is method for any case where you have doubts about whether the cast will succeed.

Thanks @Jedd, that is super helpful!

I used the is approach you recommended, which worked just fine after one change. The number is actually still an object so I tweaked your code to check if it is an object instead of float.

If I use an as approach then I get the below error:
The as operator must be used with a reference type or nullable type ('float' is a non-nullable value type)

To convert from an object to a number I’m using System.Convert.ToSingle(myFirstProp);

Maybe that is helpful for someone else. Thank you for your help and thoroughness @Jedd

Glad to hear you have something that works!

Ah and good catch

Since float type is non-nullable. the as keyword wouldn’t work.
you would need to do this blenderProperties["myFirstProp"] as float?
Which is a little messy.

1 Like