Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Official] The collected il2cpp forum topic.

Discussion in 'General Discussion' started by RalphH, May 20, 2014.

  1. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    As of 5.2, we support Android, iOS, Playstation 4, WebGL and Xbox One.

    5.3 adds support for Playstation Vita and Windows Store (when targeting Windows 10 SDK).
     
    IntDev likes this.
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    @Tautvydas Zilys - Are we ever going to get a build symbol that specifies IL2CPP? Or at least have a separate DLL mapping option for IL2CPP? This becomes very difficult for me because I have compiler symbols that designate different bits of code to be compiled depending on platform. This can break builds for Android that are set to use IL2CPP because it's different code for me than what I use for the Mono platform. The same goes for Windows 10 Universal or Windows Store Builds because I have some native .NET 4.5 / 4.6 code that compiles for those platforms when its building the final target, but if IL2CPP is used those builds will break so I need to be able to determine when IL2CPP is used.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Are you talking about source code or DLLs?

    For source code, there's ENABLE_MONO/ENABLE_IL2CPP/ENABLE_DOTNET. They do what you'd think they'd do.

    For DLLs, you should be able to specify scripting backend in plugin inspector.

     
    ZimM likes this.
  4. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Is there any reason those are not documented?..
    Also, could be useful to have an API for runtime checks (for DLLs).
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    I'd guess that's a documentation bug.

    Any particular use case for that one?
     
  6. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    To work around IL2CPP bugs when using a DLL :) I mean, what's the purpose of ENABLE_IL2CPP otherwise?
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Fair enough.
     
  8. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Also, it's not just about IL2CPP bugs... There is some stuff in IL2CPP that won't ever be possible. For example, I used runtime IL code generation with Mono, but, of course, you can't do that without a JIT compiler... So the code paths for Mono and IL2CPP can differ a lot.
     
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    That's exactly what I was referring to (both cases actually). I wasn't aware that had been added, thanks! There are only a couple of issues I'm currently working through, and haven't tested yet with Unity 5.3, but not exactly related to IL2CPP:

    When including a .NET 4.6 (.NET Core for Windows 10) DLL in my project I specify a separate DLL as a placeholder. This works as expected, however when the Unity editor is opened, the script inspector upgrade thing tries to run against that DLL and throws an error that it can't read it. Also, if that DLL is part of a .unitypackage and imported on a machine that doesn't have Windows 10, an error is displayed that it can't find {some program files path}/.NET CORE

    In both cases, builds and running in the editor still work fine, it's just an inconvenience. I need to file a bug report for this if it's not working yet in 5.3.

    Also, this isn't a bug, but do you think it would be possible to choose Xbox One, PS4, etc from the platform targets even if you don't have those SDKS? I don't have access to the Xbox One SDK for example, but my asset is compatible. If I build out a .unitypackage and map my DLLs, I have to have my users manually map those platforms since I can't map them in the Platform Settings.
     
  10. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    This is one thing I was getting at as well. There are things that will work when compiled with .NET Native, but if IL2CPP is used then it's not possible, which is why I wanted to make sure the option was there.
     
  11. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Meanwhile, you can manually map them by editing the corresponding .meta file for your DLL's.
     
    Dustin-Horne likes this.
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Dantus and Dustin-Horne like this.
  13. StealThePixels

    StealThePixels

    Joined:
    Apr 2, 2015
    Posts:
    68
    Do you plan to support Windows 8.1 as well?
    It is far from dead: http://www.w3schools.com/browsers/browsers_os.asp
    It has still larger audience than Win 10
     
  14. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @StealThePixels W3Schools is not a good source for any kind of information. They've been widely lambasted for the poor quality of content they provide. I suggest finding another source of analytics to back your point.
     
  15. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,617
    Yours isn't backed by much either. The site you've linked, which makes its agenda clear by its mocking name alone, doesn't actually say anything to explain what's bad about W3Schools. (In fact, it says they've improved.)

    Edit: If the info at W3Schools there is/was indeed dodgy then I'd love to read more about what's actually bad about it. I don't know enough myself to have any clue how solid it is.
     
    Acissathar and Dustin-Horne like this.
  16. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    W3Schools is and always has been a pretty good resource when used as a "quick reference guide". They don't provide in depth information on a lot of topics (except when using their HTML Validator), but it's good information and has provided me with a lot of useful answers over the years.
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    We might, once IL2CPP matures and if Windows 8.1 is still relevant at that point it in time. Currently, IL2CPP is still considered experimental on Windows Store, and is missing several features that the .NET backend supports (several important .NET Core APIs, as well as interoping with Windows Runtime).
     
  18. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    There are 2 links in my previous post, not 1. The other is a Google search, with quite a few blog posts with heavy opinions and hard facts. The #1, #3, & #4 results for the search are Stack Exchange questions with good, factual positions on the validity of W3Schools.

    I'm sorry, I didn't write “W3Schools is not a good source for any kind of information” to debate whether it is or not. It's well-known and widely accepted in the web design community that it is. No professional web designer trusts them any more (especially since MDN has grown to be a far, far better resource), and no level-headed business person would trust those analytics. If you want to know why, go do some searches.

    My point is only that they have a history of skewing data, having blatant inaccuracies, and outright lying. You're under no obligation to take my word for it — I'm literally inviting you to go read up on their bullshit — but if you don't, it's your funeral.
     
  19. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
  20. StealThePixels

    StealThePixels

    Joined:
    Apr 2, 2015
    Posts:
    68
  21. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    Nope, those are all reputable (or at the very least, untarnished) sources AFAIK.

    for doing your homework.
    for having to slather a layer of passive aggression on top.
     
  22. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    I'd just as soon buy the newest version of ...in a nutshell' books as dork around with waiting for browser pages overstuffed with ads to render.
     
  23. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Any news on IL2CPP for Windows/Mac/Linux? As in, 2016/2017/2018 etc.?

    IL2CPP would be incredibly useful for UNET projects (MMORPGs etc.), where the server often contains sensitive code that shouldn't be visible by clients in order to avoid cheats/exploits. Code obfuscation is not a really good option and IL2CPP would make reverse engineering infinitely harder. People could still use Disassemblers etc., but there's just no way to get back to the C# code easily. I have talked to some Unity developers about this topic, and right now the only way to deploy an MMO without providing all the source code is to publish WebGL builds - which is fine, but also comes with performance issues for big MMO projects.

    Of course, it would also be useful for people who just don't want other people to see their game's code, sensitive or not.

    The option to use IL2CPP as backend would be really awesome, even if that means that we have to work around some issues in the beginning.
     
    mh114, L-Tyrosine and Ostwind like this.
  24. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    @vis2k

    We have no news to report now about IL2CPP on standalone platforms. Releasing it is still on our internal roadmap, and when we have a more firm date, it will appear on the Unity public roadmap.
     
    ZimM and mischa2k like this.
  25. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
  27. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    Awesome @JoshPeterson at this time I'm using a php bridge because I'm not able to find any C# libs working fine with Unity using IMAP.
     
  28. JohnSmith1915

    JohnSmith1915

    Joined:
    Apr 21, 2016
    Posts:
    143
    Can the IL2CPP be a better protection against decompilation? When can be used in PC (Linux, Mac, Windows (7/8/10)?, thanks.
     
  29. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Yes in that IL2CPP targets are compiled to native code like any other c++ code. No IL or source is included so you don't get the exposure of source that you'd get with a mono build.

    Desktop platforms are on their roadmap as JoshPeterSon mentioned a couple of posts up:

     
    JohnSmith1915 likes this.
  30. EndBug

    EndBug

    Joined:
    Jun 14, 2016
    Posts:
    4
    I've checked the C++ code of an IO operation in C#, and I find that method FileStream.close() is translated into VirtActionInvoker0::Invoke, why this but not Stream_Close_m()?
     
  31. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Stream::Close() is a virtual method.
     
    Dustin-Horne likes this.
  32. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    This. You'll find that other methods are virtual as well:

    BeginRead, BeginWrite, EndRead, EndWrite, GetHashCode, ReadByte, ToString and WriteByte are all virtual methods on the Stream class. The regular Read and Write methods (as well as a few others) are abstract.
     
  33. EndBug

    EndBug

    Joined:
    Jun 14, 2016
    Posts:
    4
    IL2CPP shares generic method implementations for a generic type SomeGenericType<T> when T is:
    • Any reference type (e.g. string, object, or any user defined class)
    • Any integer or enum type
    That's found on il2cpp-internals-generic-sharing-implementation, but I use different enum types as T and find that C++ codes are not shared, Do I miss something?
     
  34. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Integers and enums aren't shared by default. That can be enabled (by setting player settings string "additionalIl2CppArgs" to "--enable-primitive-value-type-generic-sharing", use at your own risk) but comes at a performance cost.
     
  35. EndBug

    EndBug

    Joined:
    Jun 14, 2016
    Posts:
    4
    Thx, but why comes at a performance cost since enums are integers. Why can't IL2CPP sharing generic method of SomeGenericType<int> like the way it does when T is a reference type.
     
  36. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Let's say you call .ToString() on it. If it's an enum or an int, il2cpp knows exactly which method you're calling since they're both value types and you cannot inherit from value types. However, if the method is using generic sharing, il2cpp doesn't know at compile time which method has to get called, thus it needs to look it up and call it indirectly.

    There are more situations like these, but they all boil down to the fact that if you know exact type at compile time, some operations are just faster.

    Stuff like arithmetics on them will be equally as fast, since that involves no metadata.
     
  37. EndBug

    EndBug

    Joined:
    Jun 14, 2016
    Posts:
    4
    What I mean is integer and enum can share generic methods set A as default, and reference type shares generic methods set B, A and B have different method declaration. Because as I see, calls on integer or enum are the same.
     
  38. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    @EndBug

    Suppose you have some code like this:

    Code (CSharp):
    1. void GenericMethod<T>(T value) {
    2.     var valueString = value.ToString();
    3. }
    And then you make two calls:

    Code (CSharp):
    1. enum Stooges {
    2.     Larry, Curly, Moe
    3. }
    4.  
    5. GenericMethod(Stooges.Larry);
    6. GenericMethod(42);
    If IL2CPP is not sharing code between integers and enums, it knows at compile time the the call to the virtual method ToString will always call Int32.ToString in the second case. So IL2CPP emits a direct call in the implementation of GenericMethod<int>, which is faster than going through the run-time virtual method call lookup process.

    If IL2CPP is sharing code between integers an enums the implementation of GenericMethod<T> where T is an integer or an enum must always make the slower virtual method call, because IL2CPP cannot determine at compile time what the type of T is.

    So this is a tradeoff between binary size and run-time performance.
     
    larku likes this.
  39. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Josh, do managed dll get converted by IL2CPP to native code?

    And is there any difference in performance against compiling the same from source?
     
  40. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    @00christian00

    Yes, all managed assemblies are converted by IL2CPP, just as script code is converted. There is really not a difference in performance, as IL2CPP always coverts the managed IL code, not the C# code, so whether that C# code is compiled into a managed assembly that you add to the project or it is compiled to Assembly-CSharp.dll, it should not matter.

    I suppose that a managed assembly compiled with a newer C# compiler could provide better IL code than the Mono C# compiler shipping with Unity now, but I've not seen any cases where that actually happens.
     
    00christian00 likes this.
  41. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Thanks! Glad to hear it, cause I am extracting some code to put in a dll to speed up compilation time and I was worried it could get slower.
     
  42. mhalttu

    mhalttu

    Joined:
    Mar 13, 2013
    Posts:
    30
    Hi @JoshPeterson

    With Unity 5.4 the IL2CPP support on Android is official. However, we are not getting stack traces in production builds.

    At least from our perspective it feels like a very serious issue; pretty much a showstopper for using IL2CPP. If (and when) there are any exceptions or errors logged by the game, it is next to impossible to know what causes them. Consider a NullReferenceException without any stacktrace. How would you even start to analyze it?

    Are you guys aware of this problem? There is at least one issue reported about it at https://issuetracker.unity3d.com/is...t-a-stacktrace-fail-to-return-meaningful-data
     
  43. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Yes, this is a known issue.
     
  44. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    @mhalttu

    I agree, this is a serious issue. I'm checking with our Android team now, to determine its status. I'll let you know what I find out. Thanks!


    Edit: Well, I've just heard this is the top development priority for the Android team, so I would expect it to be done soon, although I don't have a timeline.
     
  45. Deleted User

    Deleted User

    Guest

    Question re: IL2CPP float expression evaluation. We have a multiplayer game with a lockstep engine, which basically means some parts of our code must run identically (bit accurate) cross-platform.

    I just tracked down a bug where iOS differs from Android/Windows because IL2CPP uses float intermediate precision when evaluating float expressions. Android/Windows on mono apparently promote to double.

    Is there any way to make IL2CPP use double for intermediate results when evaluating float expressions? As far as I can tell this is the only reason our iOS engine is not exactly matching our Android/Windows (everything else, sqrt etc, are OK).

    An example of how IL2CPP forces float intermediate precision:

    C#:
    Code (CSharp):
    1. public static float sqrMagnitude(Vector2 v) {
    2.     return v.x * v.x + v.y * v.y;
    3. }
    IL2CPP:
    Code (CSharp):
    1. // System.Single Mk_MathTest::sqrMagnitude(UnityEngine.Vector2)
    2. extern "C"  float Mk_MathTest_sqrMagnitude_m2827493274 (Il2CppObject * __this /* static, unused */, Vector2_t2243707579  ___v0, const MethodInfo* method)
    3. {
    4.     {
    5.         float L_0 = (&___v0)->get_x_0();
    6.         float L_1 = (&___v0)->get_x_0();
    7.         float L_2 = (&___v0)->get_y_1();
    8.         float L_3 = (&___v0)->get_y_1();
    9.         return ((float)((float)((float)((float)L_0*(float)L_1))+(float)((float)((float)L_2*(float)L_3))));
    10.     }
    11. }
     
  46. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    @mwk888

    I've not tried it yet, but I think that explicit casts to double might get you what you want:

    Code (CSharp):
    1. public static float sqrMagnitude(Vector2 v) {
    2.     return (double)v.x * (double)v.x + (double)v.y * (double)v.y;
    3. }
    The generated IL and C++ code will tell for sure.

    I suspect that this will be a pain to implement throughout the code base, and code easily be prone to missing cases. At the moment we don't have a global option in IL2CPP to do intermediate double precision, and I'm not sure that we can easily add one.

    Even if the C++ code ends up matching though, you'll be dealing with differences in machine code between ARM and Intel, so I'm not sure we can ever guarantee bit-accurate results.
     
  47. Deleted User

    Deleted User

    Guest

    Yes, I was hoping there was some hidden flag I could set :) but if not explicitly using double may be the fix. Naturally I was hoping to avoid that.

    Q: Another approach is we try IL2CPP for Android also, as all we really need is Android/iOS interoperation, Windows is just a convenience. What do you think between the two approaches?

    Yeah, I'm prepared to give up on Intel/ARM compatibility. Surprisingly though I have made Intel/ARM match on other projects without much trouble (thank you ANSI) but those were pure c++ so easier to control.
     
  48. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    @mwk888

    The generated C++ code is platform independent, so you should be compiling the same C++ code on Android and iOS if you use IL2CPP for both. That is probably your best option if you only need those two platforms to match.
     
  49. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    307
    Hello! Are there any current plans on supporting IL2CPP on windows and mac standalone?
    I'm an indie MMO developer trying to adapt Unity as a client and a server engine. There is a trouble with cheaters and botters having super easy access to the client code base which further complicates a very hard battle to begin with.
    IL2CPP would shift a situation in our favour which is so needed.
     
    Last edited: Sep 29, 2016
    mischa2k likes this.
  50. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    @JoshPeterson

    Can someone explain to me the future of the Mono runtime within Unity and all its target platforms?

    My understanding was IL2CPP was replacing the Mono runtime? Yet now I see with the .NET upgrade Unity will be upgrading the Mono runtime as well?

    Thanks