FlaxEngine / FlaxEngine

Flax Engine – multi-platform 3D game engine
https://flaxengine.com
Other
5.54k stars 541 forks source link

Json serialization limitation #2584

Open cNori opened 1 month ago

cNori commented 1 month ago

Issue description: when calling a Editor.SaveJsonAsset funcion, seralistaion funcion is never called on c++ side

example:

//.h
class SomeAsset : public ISerializable
{
    DECLARE_SCRIPTING_TYPE_NO_SPAWN(SomeAsset);
public:
    String CppData;
    API_FIELD() String Data;

    API_FUNCION() ApplayData()
    {
         CppData = L"Data_";
         CppData.Append(Name);

    }
    // Inherited via ISerializable
    void Serialize(SerializeStream& stream, const void* otherObj) override;
    void Deserialize(ISerializable::DeserializeStream& stream, ISerializeModifier* modifier) override;
}
//.cpp
void SomeAsset::Serialize(SerializeStream& stream, const void* otherObj)
{
        SERIALIZE_GET_OTHER_OBJ(SomeAsset);
        SERIALIZE_MEMBER(Data, CppData);
        LOG_STR("Called Serialize ?");
}
void SomeAsset::Deserialize(ISerializable::DeserializeStream& stream, ISerializeModifier* modifier)
{
       DESERIALIZE_MEMBER(Data, CppData);
       if(CppData.Find(L"Data_"))
       {
           Data = CppData;
       }
       LOG_STR("Called Deserialize");
}
mafiesto4 commented 4 weeks ago

Json assets serialization assumes that C++ and C# sides match in serializable data layout so we use C# serializer to create the asset contents. I guess, we could handle native types which implement serialization manually, the test case might be usage of GameSettings/TimeSettings/.. which have C++ serialization but were using C#-only for now inside Editor.

mafiesto4 commented 4 weeks ago

Also, Json asset editor creates C#-only instance to view/modify/save asset. This would also need to be changed in order to handle C++ object serializer.

cNori commented 4 weeks ago

Json assets serialization assumes that C++ and C# sides match in serializable data layout so we use C# serializer to create the asset contents. I guess, we could handle native types which implement serialization manually, the test case might be usage of GameSettings/TimeSettings/.. which have C++ serialization but were using C#-only for now inside Editor.

some times there is a data with cant be exposed to c# because it is a example:

or the serialisation has some compression applied to it So the Absorption of c++ and C# objects are 100% the same is wrong

Also, Json asset editor creates C#-only instance to view/modify/save asset. This would also need to be changed in order to handle C++ object serializer.

editor creates C#-only instance ye right now i use a hack in my pluginto get the c++ serialisation working