If I serialize a class in c#, can Unrealscript read it back in?

277 views Asked by At

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!

3

There are 3 answers

1
Katie Kilian On BEST ANSWER

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.

1
Jensen On

Only if you use a language-neutral serialization scheme.

The default .NET serialization providers require .NET to read the object back in. But if you use a language-neutral serialization scheme, such as plain old XML, JSON or your own predefined format, then any other language should be able to parse it if a provider is available.

0
Conor Stokes On

The format used by BinaryFormatter is fairly specific to .NET and relies on .NET type information, which is not available for easy serialization in UnrealScript.

However, JSON parsing is available in the UDK, I believe, although you will probably have to do most of the actual deserialization manually. There are multiple ways to serialize to JSON from .NET and JSON is also easy enough to serialize manually.

You can JSON.NET (http://json.codeplex.com/) for fast JSON Serialization.