Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

problem with javascript accessing C# with Windows Store (Universal 10)

Discussion in 'Windows' started by AbstractionGames, Oct 14, 2015.

  1. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    Hello,

    a project that I'm porting from Unity 4.3 to Unity 5.2.1f1 (latest) is giving me a strange problem.

    I have a bunch of javascript scripts that access plugins written in C#. The javascripts are in Assembly-UnityScript (so phase 3, according to http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html) and the C# scripts are in Assembly-CSharp-firstpass (phase 1, according to the same source). So based on that, my understanding is that the javascripts should be able to see those C# scripts, and that was indeed the case for the various platforms this project has shipped so far (although it was built with Unity 4.3).

    Now on Unity 5.2.1f1 when building for Windows Store Universal 10, I'm getting a bunch of these:

    Assets/spriteAssets/mansion/elevator_door/elevator_door_sound.js(3,22): BCE0018: The name 'tk2dSpriteAnimator' does not denote a valid type ('not found').

    Any idea what could be causing this?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Hi,

    the reason why your javascript scripts cannot see C# scripts is that by default all C# scripts on Windows Store (Universal 10) are compiled with Microsoft C# compiler (Roslyn), which targets .NET Core 5, and UnityScript compiler cannot reference such assemblies.

    To fix it, go to player settings, find compilation overrides setting and set it to "Use .NET Core partially". It will make Assembly-CSharp-firstpass.dll to be compiled with Mono C# compiler, while Assembly-CSharp.dll will still be compiled using Roslyn.
     
  3. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    Thanks, that fixes that issue!
    However with "Use .NET Core partially" now it doesn't seem like I can use TypeInfo... Tried it in a separate project as well, works with Use .NET Core but not with partially. Any idea how I can work around this?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,644
    Scripts under Plugins and Standard Assets folders go to Assembly-CSharp-firstpass, others should go to Assembly-CSharp.
    With 'Use .NET Core Partially' the later is compiled using Microsoft compiler, so arranging your scripts accordingly might help.
     
  5. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    I don't get it; I'm talking about System.Type.GetTypeInfo() and the TypeInfo type that we have to use for windows store as part of System.Reflection.

    Shouldn't this just be available regardless of the compilation overrides?
    A bunch of my plugins need this, and I suspect if I start arranging those scripts I'm gonna run in other issues
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,673
    System.Type.GetTypeInfo() availability depends on the compiler which you're using (available when used with MS Compiler which uses .NET Core, not available when Mono compiler is used), Compilation Overrides controls which compiler is used when compiling scrip.
     
  7. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    gotcha, thanks :)
     
  8. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    So I think this sets us back to square one, because if I move my plugins to Assembly-CSharp, in order to get access to System.Type.GetTypeInfo(), they are then compiled with the MS compiler, and UnityScript compiler cannot reference these assemblies, as Tautvydas Zilys pointed out; and so now I'm back to my original problem: my javascript scripts cannot see the C# scripts that I had to move in order to get System.Type.GetTypeInfo()...
     
  9. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,673
    When you say "plugins", what is it, a dll ? If so, it's already compiled, so Compilation Overrides don't affect it.
     
  10. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    no, C# source that was living in the plugins folder, e.g. ngui, incontrol,...
     
  11. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,673
    Well, there are several ways to solve this:
    • Move functionality with System.Type.GetTypeInfo to dll, that way you'll choose which compiler to use, more info http://docs.unity3d.com/Manual/windowsstore-plugins.html
    • Don't use System.Type.GetTypeInfo, use regular reflection API
    • Have System.Type.GetInfo functions in Assembly-CSharp.dll, then set callbacks in to Assembly-CSharp-firstppas.dll, so whenever somebody calls function from Assembly-CSharp-firstpass.dll, the callback would be called. For.ex.
    Code (csharp):
    1.  
    2. // Assembly-CSharp-firstpass.dll - compiler with Mono
    3. public void delegate _DoSomethingWithTypeInfo();
    4. public class Utility
    5. {
    6.     public static _DoSomethingWithTypeInfo doSomething;
    7.    // Accessible both from JS & C#
    8.    public void DoSomething()
    9.    {
    10.       _doSomething();
    11.     }
    12. }
    13.  
    14.  
    15. //Assembly-CSharp.dll  - compiled with MS compiler
    16.  
    17. public class Implementation
    18. {
    19.     public static void DoSomething()
    20.     {
    21.        TypeInfo t = typeof(something).GetTypeInfo();
    22.     }
    23.  
    24.     // Call this somewhere in the begining of your game
    25.     public static void InitializedCallback()
    26.     {
    27.        Utility.doSomething = DoSomething;
    28.     }
    29. }
    30.  
    31.  
     
  12. AbstractionGames

    AbstractionGames

    Joined:
    Feb 12, 2014
    Posts:
    24
    third option looks good, I'll give it a try, thanks :)