Speckle Core - Send doesn't send convert list to base

Hello Speckle Team!

I’m working on a tool which utilizes Speckle as the medium of data transfers. In this project we have two classes that inherit from Speckle’s Base class. For reference see below:

public class Class1: Base
{
        public string Property1 { get; set; }
        public string Property2 { get; set; }
        public string Property3 { get; set; }
        public Base Mesh { get; set; }
        public List<Class2> ListOfChildrenObjects;
}

public class Class2: Base
{
        public string Property1 { get; set; }
        public string Property2 { get; set; }
        public string Property3 { get; set; }
}

As of now, we use the above classes to transfer data from Unity to Revit and vice versa. Even though receiving the data using the Operations.Receive() method works fine, I have trouble sending a list of data back. In particular, when trying to add the list of objects of class 1 to a base object before sending, the list of class 2 children doesn’t convert and hence, when I receive it back and convert it to class 1 objects, the list of class 2 objects of every class 1 object is empty. I tried converting class 2 objects to Base objects before sending, using arrays instead of lists and converting the list of class 1 objects to a json format before sending, but to no avail. Is there something I am missing and what you would be a solution to the above problem? For reference, I attach my send method below:

public async void SendData()
{
            var @base = new Base();            
            @base["objects"] = listOfClass1Objects;
            var transport = new ServerTransport(CurrentAccount, CurrentStream.id);
            string message = "Updated";
            _ = await Helpers.Send(CurrentStream.id, @base, message);
}

Thanks in advance!

Preliminary brainwave: I’d add some {get;set} to your list prop too, and see if that changes things. It might be because there’s no public setter method on the prop we cannot, on deserialisation, set it :slight_smile:

public class Class1: Base
{
        public string Property1 { get; set; }
        public string Property2 { get; set; }
        public string Property3 { get; set; }
        public Base Mesh { get; set; }
        public List<Class2> ListOfChildrenObjects {get; set;} // here
}

If that’s not making things work, a followup would be to see if the data is actually set on the object after you’ve sent it the second time. (Saying back to you so you can double check i’ve understood: you receive a Class1 object in unity, you add to it’s ListOfChildrenElements prop another or more Class2 objects, you send this, and when you receive it, the prop itself is empty)

1 Like

Hey Dimitire, adding the { get; set; } thing actually worked. Thank you so much. Such a silly mistake. Also, yeah, that’s the thing we’re doing.

1 Like