Search Unity

UnityScript to C# Conversion Tool

January 8, 2019 in Technology | 3 min. read
Topics covered
Share

Is this article helpful for you?

Thank you for your feedback!

Do you have any older projects that use UnityScript? If so, you might be interested in our open source UnityScript to C# conversion tool available to download now.

Back in August 2017, we have begun the deprecation process for UnityScript, a JavaScript-like scripting language, and started working on a conversion tool from that language to C#. Shortly after that, we moved the menu option used to create new UnityScript scripts under Legacy.

Since then we’ve collected a lot of feedback and fixed a bunch of issues in the conversion tool. To name a few changes motivated by your feedback:

  • Support for preserving comments from original scripts
  • Introduced an Editor Integration Package to simplify usage
  • Improved support for a number of UnityScript constructs

With Unity 2018.2, we removed the option to create new UnityScript scripts completely. Now we believe that the conversion tool is feature complete and stable enough to help any of you that still have projects using UnityScript.

Before starting the conversion process, we suggest that you make sure your project builds cleanly on Unity 2018.1, all of your tests are passing and you understand the limitations listed here.

We recommend running the conversion tool through the menu Tools/Convert UnityScript to C#. If you need more control over the parameters used during the conversion you can run the conversion through the command line but keep in mind that the extra flexibility comes with extra complexity.

As an example, the video below outlines the process of converting an older version of Angry Bots project. The intent of this is only for demonstration purposes whence we simply commented out any code causing compilation errors when first open the project in 2018.1.

This content is hosted by a third party provider that does not allow video views without acceptance of Targeting Cookies. Please set your cookie preferences for Targeting Cookies to yes if you wish to view videos from these providers.

To summarize, the basic process should be something like:

  1. Backup your project
  2. Open project in 2018.1
  3. Accept API Updater offer (if any) and fix remaining errors
  4. Make sure player builds successfully on each target platform
  5. Make sure all related tests are passing (also, run the project on real devices)
  6. Install the latest Editor Integration Package (see here for instructions on how to install asset packages in the Editor).
  7. Clean editor console
  8. Run the conversion tool.
  9. Fix any remaining issues (running related tests)
Note that if your project targets multiple platforms, you may need to repeat step 8 for each target platform by selecting the platform before running the conversion tool, and then manually merge the converted code, wrapping the code with conditional code accordingly.  This is a limitation of the tool. In this case, you’ll probably use a VCS to restore the state of the project after each conversion.

Step 9 may or may not be required (it depends on which APIs your project uses), but in the Angry Bots example, we needed to fix some API usages.

Since the tool is open source, you’re invited to download its source and look around! Please feel free to contribute any fixes/improvements.

If for any reason this tool does not fit your needs you may want to check other converters available on the Asset Store.

Finally, if you need any help with the tool please ask in this forum thread and we’ll do our best to help you.

January 8, 2019 in Technology | 3 min. read

Is this article helpful for you?

Thank you for your feedback!

Topics covered