Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

UnityScript 2 CSharp conversion tool

Discussion in 'Experimental Scripting Previews' started by AdrianoVerona_Unity, Aug 11, 2017.

  1. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Kinda - the UnityScript code is partially compiled (not into executable code, but into an Abstract Syntax Tree, which is one of the intermediate data structures within the compiler), and then mapped to C# from there.
     
    John-B and AdrianoVerona_Unity like this.
  2. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    Not sure why you don't get the same error when compiling your project; maybe the converter is setting UnityScript compilation to *strict mode*.

    Regardless, it looks like you have two classes that depend on each other and UnityScript compiler cannot automatically generate these classes (I guess these types does not define classes explicitly but instead simple define a bunch of methods in their respective sources)

    I guess the easiest fix would be to double check if that is the case and declare`HappyCoinFlickControl` as a class explicitly.

    Adriano
     
  3. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Working in 2018.2 on my old Mac, preparing to move various iOS projects to C# ... installing the package gives this Unity console error:

    "Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs(297,52): error CS0246: The type or namespace name `Assembly' could not be found. Are you missing `System.Reflection' using directive?"

    I understand the word "be" and a couple others... any leads on next steps?

    Are there more steps to the installation than I'm aware? I downloaded/unzipped both the "tool" and package, but the "tool" came with no further installation instructions, so my guess was the package wil ask me locate the "tool" when needed? If not, how do I connect the Unity package to the "tool"? (Alternatively, is there a way to use the command line version on the Mac? I only see a Windows .exe, plus self-build instructions that rely on Windows-only "nuget.exe.")

    I know Mac users must install Mono, and I did so. And I know 2018.2 is expected to give a warning to be ignored—but not this error during convertor installation itself.

    TIA!
     
    Last edited: Jan 8, 2022
  4. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    Which version of the package have you installed?

    Based on your error, it looks like you are not running on 2018.2 ?

    If you looks around that line in the source code (https://github.com/Unity-Technologi...Sharp/Editor/UnityScript2CSharpRunner.cs#L290) you'll see that it should not be compiling it on 2018.2.

    Can you share your Editor.log ?

    Best

    Adriano
     
    Morgan likes this.
  5. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Thank you, Adriano! That was it. I had screwed up in the Hub—thought I had assigned the project to 2018 but I hand't. Once I did so, the package installs without error.

    Now, though, when I run the package from the Tools menu, before it even does anything it fails with this error—which sounds Windows-related though I'm on a Mac:

    Win32Exception: ApplicationName='/Applications/Unity/Hub/Editor/2018.2.21f1/Unity.app/Contents/Tools/7za', CommandLine='e '/Users/mainuser/Documents/Bolster New Trip's Treasures/Trips Treasures 2021/Assets/UnityScript2CSharp/UnityScript2CSharp_*.zip' -o/var/folders/g3/5g50wp_s0lx7h_c1zr2yn5xm0000gn/T/Unity3D/UnityScript2CSharp -y', CurrentDirectory='/Users/mainuser/Documents/Bolster New Trip's Treasures/Trips Treasures 2021/Assets/..'
    System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
    System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
    System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo)
    UnityScript2CSharpRunner.TryExtractConverter (System.String assetsFolder, System.String unityInstallFolder, System.String& converterPath) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:127)
    UnityScript2CSharpRunner.Convert () (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:95)


    (If that means I need to use the command line version, how do I do that on the Mac?)

    Thanks in advance!
     
  6. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    no, this is not a Windows specific exception;

    it looks like it is complaining about the invocation of Applications/Unity/Hub/Editor/2018.2.21f1/Unity.app/Contents/Tools/7za

    does this application exist in that folder?

    are the paths (zip file, output, etc) valid ?

    you can use the command line on a Mac but that is not required; the package should also work.

    in the worst case you can extract that zip file manually somewhere on your drive and change UnityScript2CSharpRunner.cs to point not try to uncompress it, but instead, use the folder you extracted manually...


    Adriano
     
  7. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Those paths were all correct—but you led me to a fix... The Unity project is contained within a parent folder containing an apostrophe ("Trip's")... And when I tried taking the apostrophe out and starting fresh, the error was gone and convertor does start from the Tools menu. Something doesn't like that character being in the paths.

    New error now. This may be the relevant portion?

    Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations/win32_development_mono/Data/Managed

    Found assemblies root folder at '/Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations/win32_development_mono/Data/Managed'

    The version of Unity passed as the Unity Editor path is too old. Details: Could not find the module assembly folder.

    And here's the full verbose log. Thanks again for your help!

    Code (CSharp):
    1. UnityScript2CSharp was not able to convert your project:.
    2.  
    3. Probing /Applications/Unity/Hub/Editor/2018.2.21f1
    4. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation
    5. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en
    6. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/Manual
    7. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/Manual/docdata
    8. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/ScriptReference
    9. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/ScriptReference/docdata
    10. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles
    11. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/ScriptRefImages
    12. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/css
    13. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/images
    14. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/images/favicons
    15. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js
    16. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback
    17. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master
    18. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/css
    19. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/fonts
    20. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/fonts/font-awesome
    21. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/fonts/oxygen
    22. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/img
    23. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/js
    24. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/js/dist
    25. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/js/lib
    26. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/js/src
    27. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFiles/js/feedback/five-star-rating-master/sass
    28. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual
    29. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/css
    30. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/images
    31. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/images/favicons
    32. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js
    33. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback
    34. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master
    35. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/css
    36. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/fonts
    37. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/fonts/font-awesome
    38. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/fonts/oxygen
    39. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/img
    40. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/js
    41. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/js/dist
    42. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/js/lib
    43. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/js/src
    44. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/StaticFilesManual/js/feedback/five-star-rating-master/sass
    45. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads
    46. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/Examples
    47. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/ExpertGuides
    48. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/GlobalIllumination
    49. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/Main
    50. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/SL
    51. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/Shaders
    52. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/Documentation/en/uploads/Textures
    53. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines
    54. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport
    55. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Managed
    56. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Source
    57. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Source/WindowsPlayer
    58. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Source/WindowsPlayer/UnityPlayerStub
    59. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Source/WindowsPlayer/WindowsPlayer
    60. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations
    61. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations/win32_development_mono
    62. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations/win32_development_mono/Data
    63. Probing /Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations/win32_development_mono/Data/Managed
    64. Found assemblies root folder at '/Applications/Unity/Hub/Editor/2018.2.21f1/PlaybackEngines/WindowsStandaloneSupport/Variations/win32_development_mono/Data/Managed'
    65. The version of Unity passed as the Unity Editor path is too old. Details: Could not find the module assembly folder.
    66.  
    67.   at UnityScript2CSharp.Program.AppendUnityAssembliesReferences (System.String unityAssembliesRootPath, System.Collections.Generic.List`1[T] references) [0x00041] in <ff3d7f3450004323a9bfd3f6a35bb770>:0
    68.   at UnityScript2CSharp.Program.AssemblyReferencesFor (UnityScript2CSharp.CommandLineArguments options, UnityScript2CSharp.AssemblyType assemblyType) [0x0007d] in <ff3d7f3450004323a9bfd3f6a35bb770>:0
    69.   at UnityScript2CSharp.Program.ConvertScripts (UnityScript2CSharp.AssemblyType assemblyType, System.Collections.Generic.IList`1[T] scripts, UnityScript2CSharp.UnityScript2CSharpConverter converter, UnityScript2CSharp.CommandLineArguments args, System.Collections.Generic.List`1[T] referencedSymbols, System.Collections.Generic.HashSet`1[T] compilerErrors) [0x0000d] in <ff3d7f3450004323a9bfd3f6a35bb770>:0
    70.   at UnityScript2CSharp.Program.Main (System.String[] args) [0x00307] in <ff3d7f3450004323a9bfd3f6a35bb770>:0
    71. Consider running converter with '-i' option.
    72.  
    73. UnityEngine.Debug:LogError(Object)
    74. UnityScript2CSharpRunner:ShowConversionResultsInConsole(Int32) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:236)
    75. UnityScript2CSharpRunner:RunConverter(String) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:215)
    76. UnityScript2CSharpRunner:Convert() (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:97)
    77.  
    (The current build target is set to Mac FWIW, although I will be publishing to Windows, Mac, and iOS.)

    And If I need to go back to 2018.1 I can (I'd have to redo my latest changes though—I went to the last version that support JS before realizing the conversion tool might complain).
     
  8. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    Odd.

    I somehow screwed it up :(

    I've fixed this bug a long time ago (https://github.com/Unity-Technologi...mmit/0177ddd3a2168426c827e350ce76ae5c557d4d10) but somehow the latest release version of the converter does not include that fix.

    I'll try to generate a new release in the next couple days

    That being said, note that:

    1. This tool is considered unsupported so I'll do that at my free time.

    2. Unrelated to 1, but important: since you are targeting multiple platforms, you may need to do some extra work to make sure all the necessary code is converted; more precisely, if your projects contains conditional code, i.e, code wrapped around #if SYMBOL (the converter will report a list of such symbols if there any). See the readme file for more details: https://github.com/Unity-Technologi...-code-is-not-included-in-the-converted-csharp

    Best

    Adriano
     
    Last edited: Jan 13, 2022
    Morgan likes this.
  9. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Much appreciated, Adriano! It makes the difference on several pretty big projects that won't have to perish :)

    Thankfully, I have no if-symbols in any of these projects.

    I do expect I'll have to do some work, though—the conversion will be a starting point, and I'm ready to debug my code from there.
     
    Last edited: Jan 14, 2022
    AdrianoVerona_Unity likes this.
  10. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    you are welcome

    Depending on the # / size of the projects it may worth (and I highly encourage you) to customize the converter code to tweak it for your own needs (for example, instead of trying to workaround how some piece of code is being converted, it may worth changing the converter to output the way you want it to be)


    Definitely you will have some extra work; as I said, it may be worth investing in customizing the converter

    Adriano
     
    Last edited: Jan 16, 2022
    Morgan likes this.
  11. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    @Morgan can you please try with the version attached? I've fixed a couple of issues in addition to the one you hit (if this works I'll publish at github).

    Adriano
     

    Attached Files:

    Morgan likes this.
  12. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    That version worked perfectly (on Mac) on this project. Thank you!

    When conversion was done, I had to fix literally one single line of code (a UI recttransform.localScale that was Vector2 instead of Vector3) and now, as near as I can tell, my game is fully up and running, ready to publish.

    The code looks nice and readable with my old comments intact. Very nice!

    Now on to the other, larger titles...
     
    AdrianoVerona_Unity likes this.
  13. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    Glad to hear that.

    Later today I'll "publish" that version to github

    Please note that I strongly recommend you to do a full code review on the converted code, as detailed as you can, before moving on.

    Adriano
     
    Last edited: Jan 17, 2022
    Morgan likes this.
  14. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Yes, I'll be doing lots of checking and testing, especially for the two more complex games.

    (I'm familiar with the command line. If I decide to use that version change options, how would I do that on Mac? It looks like a Windows.exe. And building it myself reqiures other Windows-only .exes?)
     
    AdrianoVerona_Unity likes this.
  15. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    it is a simple C# console application. It runs on Mac, Linux & Windows

    since it is a C# command line application you should be able to build it without problems on a Mac, providing you have the correct dotnet SDK installed. AOT it targets DotNet 4.6.1 but I am pretty sure you should be able to use a newer version (maybe even target netstandard 2.1)

    The easiest way I can think is to run it through the editor integration package and copying the passed arguments from the log.

    Adriano
     
    Morgan likes this.
  16. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    Morgan likes this.
  17. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Thanks! That clarifies things. Great tool to have!
     
    AdrianoVerona_Unity likes this.
  18. zelkey_zk

    zelkey_zk

    Joined:
    Sep 13, 2021
    Posts:
    4
    Hi! Just came across unityscript2csharp on github, because I have an old project that still use UnityScript, I wanted to use this tool, so that I can revamp the game in C#. but my problem is, I can't convert them because there are a lot of Object reference not set to an instance of an object warning I'm getting, and it wants me to run the converter with '-i' option. How do I that exactly? Do I need to create a .bat file? I'm a bit confused. Please help. :)
     
  19. nekoneko777

    nekoneko777

    Joined:
    Sep 11, 2013
    Posts:
    45
    Hello
    I might be late on this. we are trying to convert old project to C# now.
    I have seen a lot of postings saying about the errors "does not denote a valid type", and I am one of them.
    Seems quite common so I was hoping I can find the solution but so far no luck.

    Code (CSharp):
    1. UnityScript2CSharp was not able to convert your project:.
    2.  
    3. UnityScript2CSharp 1.0.8052.30790
    4. Probing C:/Program Files/Unity/Hub/Editor/2018.1.9f2/Editor
    5. Probing C:/Program Files/Unity/Hub/Editor/2018.1.9f2/Editor\BugReporter
    6. Probing C:/Program Files/Unity/Hub/Editor/2018.1.9f2/Editor\BugReporter\imageformats
    7. Probing C:/Program Files/Unity/Hub/Editor/2018.1.9f2/Editor\BugReporter\platforms
    8. Probing C:/Program Files/Unity/Hub/Editor/2018.1.9f2/Editor\Data
    9. Probing C:/Program Files/Unity/Hub/Editor/2018.1.9f2/Editor\Data\CGIncludes
    1. using Unity 2018.1.9f2
    2. installed UnityScript2CSharp_Conversion_1.0.8052.30790.unitypackage
    3. Convert (verbose logging) and the error is attached.

    I also used -i argument to ignore the compiler errors. when I did that, it processed 20 files then stops with the same "does not denote a valid type" errors.

    I have never written code with UnityScript (this is from other engineer) so it's really hard to track down.
    Please help.
     

    Attached Files:

    Last edited: Nov 15, 2023
  20. nekoneko777

    nekoneko777

    Joined:
    Sep 11, 2013
    Posts:
    45
    I just had to run it with -i option today, and hate using command line so modified the source code like this. It works though it's hacky. don't forget to remove it after use.
    Code (CSharp):
    1.         args = args + " -i";
    Insert this line in the UnityScript2CSharpRunner.cs::line 283.