diff --git a/Source/Engine/Serialization/SerializationFwd.h b/Source/Engine/Serialization/SerializationFwd.h index de129d5d8..7917fc52e 100644 --- a/Source/Engine/Serialization/SerializationFwd.h +++ b/Source/Engine/Serialization/SerializationFwd.h @@ -76,3 +76,18 @@ class ISerializeModifier; if (e != stream.MemberEnd() && e->value.IsBool()) \ member = e->value.GetBool() ? 1 : 0; \ } + +// Explicit auto-cast for object pointer + +#define SERIALIZE_OBJ(name) \ + if (Serialization::ShouldSerialize((const ScriptingObject*&)name, other ? &other->name : nullptr)) \ + { \ + stream.JKEY(#name); \ + Serialization::Serialize(stream, (const ScriptingObject*&)name, other ? &other->name : nullptr); \ + } +#define DESERIALIZE_OBJ(name) \ + { \ + const auto e = SERIALIZE_FIND_MEMBER(stream, #name); \ + if (e != stream.MemberEnd()) \ + Serialization::Deserialize(e->value, (ScriptingObject*&)name, modifier); \ + } diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 138291177..86bd3dcd4 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -1799,6 +1799,12 @@ namespace Flax.Build.Bindings { if (memberType.IsBitField) return "_BIT"; + if (memberType.IsPtr) + { + var t = FindApiTypeInfo(buildData, memberType, caller); + if (t.IsScriptingObject) + return "_OBJ"; + } return string.Empty; }