Can't pass custom structs to ray remote C++

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

Hi I’m having issues passing custom a custom struct to the ray Actor. This is how my code looks like:

#include <ray/api.h>

typedef struct ex_struct_s
    long x;
    long y;
} ex_struct_t;

class Counter
    int count;
    ex_struct_t ex_st;

    Counter(int init, ex_struct_t init_st)
        count = init;
        ex_st = init_st;
    /// static factory method
    static Counter *FactoryCreate(int init, ex_struct_t init_st) { return new Counter(init, init_st); }

    /// non static function
    int Add(int x)
        count += x;
        return count;

/// Declare remote function
RAY_REMOTE(Counter::FactoryCreate, &Counter::Add);

int main(int argc, char **argv)

    std::vector<ray::ObjectRef<int>> actors;

    for (int i = 0; i < 10; i++)
        ex_struct_t ex_st_i;
        ex_st_i.x = 0;
        ex_st_i.y = 1;
        ray::ActorHandle<Counter> actor = ray::Actor(Counter::FactoryCreate).Remote(i, ex_st_i);
        /// actor task
    for (int i = 0; i < 10; i++)
        int actor_task_result = *(ray::Get(actors[i]));
        std::cout << "actor_task_result = " << actor_task_result << std::endl;
    return 0;

The error I get:

error: 'struct ex_struct_s' has no member named 'msgpack_unpack' v.msgpack_unpack(o.convert());

Is there another way to pass this custom struct?

I think adding this MSGPACK_DEFINE(x, y); to the struct definition solves it for this simple example, but I’m looking for a better way to do it, just in case there are a lot of structs or in case of complex structs.

Yep, you need to add MSGPACK_DEFINE to ensure your structs is messagepackable currently. Another choice is using bytes and you can serialize the structs by yourself.