Search Unity

Unity and their API

Discussion in 'General Discussion' started by Manato, May 10, 2019.

  1. Manato

    Manato

    Joined:
    Jun 11, 2015
    Posts:
    26
    Hi,
    I'd like to discuss about the limit of the Unity API and what should be changed.

    Unity API Currently
    Currently, you have access to the Unity API only via the C# scripting language. It is possible to write plugins in C for Unity, but it is very limited and not that what I have in mind.

    What should change
    Unity should expose their API not only to C#, but in general. I think Unity is written in C/C++, so let us write code in C/C++ or other language that compiles to machine language like Rust or Golang!
    Rust doesn't even need a garbarge collector it has its own memory management with ownerships!
    In this way, I can write fast running code and don't have to worry about garbage collection. I can even write my own scripting language (really, C# is bad as a scripting language!)

    The down sides
    While compiling directly to machine language it's not possible to write 'once and run everywhere code' like with C#.
    I think, that's the reason why the Unity team will never expose their API, because it does not fit in their business concept. Unity is an engine to provide your game to any plattform.

    But I think it would be the right choice. I like Unity I really do! But it feels like writing code 10 years behind!
     
  2. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    142
    Unity used to do three things badly.

    Now it does one thing well. This is because over time the burden of supporting 3 languages was eating into resources that could be used to further the engine.

    But if you really want to write C++ in Unity this guy might have you covered

    https://github.com/jacksondunstan/UnityNativeScripting
     
    dadude123 likes this.
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    5,610
    And your solution to that is to... code like you're 30 years behind?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,676
    But.... why? Just choose IL2CPP if you want your code compiled to machine language as it is.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,246
    It's not that Unity doesn't expose a native API. It's more like there is no native API. Large portions of Unity are written in C#. The parts are not are written to be consumed by Mono/IL2CPP runtimes. Exposing a language independent API would be like rewriting half the engine. It's not going to happen.
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,037
  7. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,157
    You can also already write code in C/C++/Go/Rust/whatever, you just have to do it as a library which doesn't directly call Unity APIs.
     
    Joe-Censored and GameDevCouple_I like this.
  8. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,721
  9. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,037
    For that matter here is an implementation of Lua for Unity that might work as a starting point (if not the code itself, then perhaps the implementation details) for getting another language like Rust or Golang into Unity.

    https://github.com/Tencent/xLua
     
  10. Manato

    Manato

    Joined:
    Jun 11, 2015
    Posts:
    26
    I think you guys don't get my point.
    Your solutions are well known, but does not solve the current problem.
    I don't want my code to transpile to C/C++ or bind to C#, I don't want this extra overhead. I want to have access to Unity via an API. It is possible but only with C#. But I need more control of my memory and may use another scripting language without the overhead of C#.

    If it is already possible in Unity, enlight me!
     
  11. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    5,610
    What specific limitations are you dealing with? None of this theoretical stuff. What's wrong NOW?
     
    Last edited: May 17, 2019
  12. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,197
    I'm pretty sure Unity have embraced the DOTS future and various things that enable all sorts of efficiencies at runtime etc. So they are wedded to enabling people to do stuff in C# that is performant. As such I dont see them investing effort in other languages or alternative, performant things in the years ahead.
     
    Joe-Censored, Ryiah and dadude123 like this.
  13. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,197
    So my advice would be, read up on the detail of DOTS and if it still doesnt fit and you are wedded to c++, choose a different engine that makes more sense for this.

    https://unity.com/dots

    And especially this particular article may be of interest: https://blogs.unity3d.com/2019/02/26/on-dots-c-c/

    Just one example:

     
    Last edited: May 17, 2019
    Peter77 and GameDevCouple_I like this.
  14. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,607
    What exactly is it your doing that unity is not performant enough to perform in its current version?

    Im sorry but it does really sound like your talking about hypotheticals, have you actually tried doing whatever it is you need to do?

    I doubt your doing anything that cannot be done currently, so this is probably the age old issue of "over optimisation / micro optimisation" rearing its head once again, through yet another user.

    Give us examples of what you tried to do that didnt work and how you did it, more than likely its the way you went about it than a limitation of the engine - and we can help you with that.

    If however this is simply because you are a c++ programmer and you have been taught that c++ is super performant etc etc, then I urge you to actually use the engine first for whatever it is your trying to do, and then come back if you actually find its not possible because of performance reasons.

    Honestly though I am sure this is not really an issue, just one in your mindset.
     
    Joe-Censored, Ryiah and SparrowsNest like this.