I am trying to figure out a way to pass large amounts of information between C# and Unrealscript. One of the things I am trying to investigate, is if C# can serialize a class for UnrealScript to later read in.
Serializing in C# is not so bad:
InfoToSerialize myInfo = new InfoToSerialize();
myInfo.i = 1;
myInfo.j = 2;
myInfo.str = "hello";
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, myInfo);
stream.Close();
This little snippet of code successfully produces a binary file called MyFile, which looks quite serialized. if you open it in a notepad application, most of the data there is composed of unreadable symbols and icons.
My question: Is it then possible to have UnrealScript gain access to this file and de-serialize it? My research on this topic so far makes it seem like it is not possible, but perhaps somewhere here has had some experience in this area. I know that UnrealScript has its own save and load functionality, but I am not sure if that will aid me in this task. Any information is greatly appreciated!
It is possible, but it might take some extra work on your part, depending on what is available in UnrealScript. The .NET framework supports several different serialization schemes. The default method is to serialize to an internal binary format. That works great if you need to read and write from the same .NET program (and as long as your program can handle upgrades -- binary serialization can break between different releases of the .NET framework). But this won't work at all in your case -- you need to be able to read the object from a program not written in the .NET framework.
Fortunately there are also ways to change your serialization methods. You can choose to serialize, for example, to XML. At the far end of the spectrum, if no serializers provided by the .NET framework can be read by UnrealScript, you can write your own serializer that writes to whatever format you require.
This MSDN link has more information about serialization.