Unity3d XML Object/Class/Type Serialisation Attributes

In an earlier post I post the basics of parsing xml to a class/object of type, below are the correct attributes to help the parser with coercion of values, type and values to ignore etc, which helps speed things up dramatically obviously, in this example we take some arbitrary XML as below:-

And in unity for this xml would have the class set with the following xml attributes (note the use of List ‘using system.collections.generic;’ ):-

And to take the xml text and parse it to the object:-



By |November 17th, 2013|Unity 3D|Comments Off on Unity3d XML Object/Class/Type Serialisation Attributes

Unity3d XML Object/Class Serialisation (the basics)

A friend of mine was asking about how you can save the scene hierarchy and object/script properties  in Unity, he had written most of the code instantiating prefabs and was already busy setting variables via interactions in his scripts. I explained that although I do have a generic reflection based method, that can save/restore the hierarchy, gameobjects, transforms, materials & script variables ( used on the space application ), it would be too verbose and unfitting for this task, plus if his script and prefab scripts were not written the right way this approach may not work.

With simpler configuration apps a much simpler class based object oriented approach is all that is required and most cases it is better to start with that system in mind than to retro fit. It is also much better if bringing in xml /json from other sources to reflect the xml/json structure with a c# class which you can then attach methods to manipulate the data, rather than hand parse each node (after learning the hard way), something that might be appropriate with collada objects perhaps.

Update: The methods below how to correctly set xml attributes in c# to coerce your values from the xml to your class see the latest post:-

Unity3d XML Object/Class/Type Serialisation Attributes

Below is an older very simple one script demonstration of instantiation and recording values to and from XML in Unity, apologies for any errors or messy logic I think I only had an hour to write it one afternoon, but hopefully it will convey the basics, but I would use the above attributes in c# see the link above over the method below for helping the xml parser […]

By |September 2nd, 2013|CodeBlog, Unity 3D|Comments Off on Unity3d XML Object/Class Serialisation (the basics)

Unity 3D – Add A Short Cut To Desktop C# – Hack Method

Having to create a short cut to the desktop for an app seems easy if you do it manually, most of the programmatic ways I have so far found on the internet involve referring to a COM Library/Component to facilitate this, any how here is a slightly hacky version that seems to work for me found on a forum which I have adapted to take data from unity etc

Warning! This method relies upon writing and executing a visual basic script to create the short cut, security measures on some machines may not allow this so be warned.


By |August 28th, 2013|Unity 3D|Comments Off on Unity 3D – Add A Short Cut To Desktop C# – Hack Method

Unity3d Process Calls, Zipping, Command line and Window console Snippets

Recently being making a little utility app for transporting and playing local  html5/jquery based presentation from pc to ipad etc, below are some snippets of code for starting stopping other apps such as chrome browser, cmd.exe, I did these in xamarin/mono really easily however the transfer to  unity was a little taxing on the more involved processes, certainly adding /C before a command line argument was new to me, strangely. Below also includes some code for zipping files in unity3d using 7-zip of 7za.exe, although I’ve used internal .net libraries before sometime 7za for a unity windows stand alone solution is certainly quick and easy.

Unity3d/.Net c# code:-



By |August 27th, 2013|CodeBlog, Unity 3D|Comments Off on Unity3d Process Calls, Zipping, Command line and Window console Snippets

Remove Invalid Filename Path Characters

If you find yourself having to strip illegal chars from user input, as I have found myself doing on numerous occasions when dealing with files and directory paths in Unity, it is always a good idea to have a method/function handy and at the ready, there are of course many ways to do this and I know that some would lean towards Regex as I have also done in the past, but here’s my adapted unity 3d – c# .net offering that also does what it says on the tin.