So... actually I don't found any solution for successfully send object, but definitely we shouldn't use string as ondesic offered(if only we pass the json string, I'd looked at this variant, but don't get proper result), it's better to use dictionary cuz it has simular key(var name) - value
structure.
So, okay, let's try dictionaries
I've found very interesting Serialization/Deserialization functions: inst2dict and dict2inst, so, let's try 'em. Problems?:
1. If you have _init()
in the instance or in instances in its properties, then it must don't have any required arguments in the _init()
- Github issue about
2. Also there's problem in deep converting, cuz only main inst/dict will be converted(GitHub issue about), their properties will not. So, ya need to make it by yourself... I have a code that doing that:
func inst2dict_properties_of_inst(inst):
for property_name in get_property_names(inst):
var property = inst.get(property_name)
if typeof(property) == TYPE_OBJECT:
inst.set(property_name, inst2dict(property)) # IT'S CHANGING ORIGINAL INST TOO!
func get_property_names(obj : Object) -> Array:
var property_names = []
var property_list := obj.get_property_list()
var i := 1
while true:
var property_name = property_list[-i]["name"]
if property_name == "Script Variables":
break
else:
property_names.append(property_name)
i+=1
return property_names
Also you need to deserialize it:
for key in dict:
if typeof(dict[key]) == TYPE_DICTIONARY:
dict[key] = dict2inst(dict[key])
- If your instance have some built-in instance in its properties like a Line2D you gonna have problems, cuz built-in objects doesn't have any script and then can't be converted... - GitHub issue about - So, I didn't found some good solution for it and don't know how to make it by myself. There's only one built-in object in my properties, it's named
"line"
and it's Line2D so I just added this condition into deserialization func:
if typeof(squad[key]) == TYPE_DICTIONARY and key != "line":
My final solution:
Kinda messy... I've thought the same, so I managed to make simplify my instance, so I can have all necessary info without containing in properties any objects and just create with it the dict and pass it in rpc and that's works, on the other computer all I need to do it's create complete instance by received minimal info, so I satisfied with it.
Hope this long post is useful. Maybe I'll think of some more elegant solution, that will be without many troubles pass whole object, not just little info, but can't promise anything.
Updated: I've found how to allow_object_decoding
, but I will not assign it as accepted cuz I didn't tried it, but it might works, so look below.