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. Dismiss Notice

Question Which script way to go?

Discussion in 'General Discussion' started by VentaGames, Jun 13, 2023.

  1. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    122
    Hi there,

    I'm thinking to integrate Lua into my game to avoid releasing frequent builds. But also Python nowadays is becoming more popular. So, is the question be asked: to Lua or to Python?
    Your opinions are in very high demand. Before i will make a step over the point of no return.

    Thanks.
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    For unity engine natural choice would be to avoid both of them and use C# instead. You'll still need to release a "build" when you update script files, it doesn't matter much if it rebuilds dlls or not, people will still need to download an update.
     
  3. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    122
    But, the scripts can be uploaded into the game from the backend. So, you don't need then new builds. The same way how Remote Config works.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    For python you need fetch whole python environment to allow modding.

    While lua has much simpler dll implementation.

    Sayin that, you will loose many functionality and performance. Plus you are opening to GC if you are not careful.

    Debugging will be your night meres.

    You can use Unity just fine to be able do modding, withouth needing python or lua. Just create game data driven, it will be challange already, if you haven't work in this paradigm.

    Unity does support addresables as well.

    And also, there are utilities, which can turn you game into moddable, while being able to attach dlls.
     
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    And why would you want that? You normally want to be dead sure about which version of the game the user is running, to debug stuff faster.

    If you insist on making your life interesting using a 3rd party language, use lua. That's because it is frequently used for scripting, and I only know one action game that ever used python for scripting. It was severance aka Blade of Darkness. Granted, renpy uses python in visual novels, but crashing python scripts with a stack trace are fairly common.
     
  6. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    122
    To all.
    I never thought that way! Personally, i never liked to integrate any third-party langs, etc...
    I just looked over the internet for solutions for changing some NPC's behavior, weather conditions, and spawning logic for some objects. I found that Lua was used by game devs for years. But you're saying that Unity has enough tools to achieve all these. I'm right?
    Then i'll continue my research in that way. Thanks
     
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    Basically, Lua or Python scripts will be a foreigner in your unity code. With C# you'll be able to drive monobehaviors. With Lua or Python that will require babysitting and glue code to get functionality you get by default with C#. Note that some advanced lua/python bindings that I'm not aware of may exists and provide functionality.

    Normally unity game do not integrate other languages. They use C# for scripts.

    If you really need a 3rd party, also take a look at miniscript. I believe it is maintained by one of the forum members.
     
    JoeStrout likes this.
  8. kvfreedom

    kvfreedom

    Joined:
    Mar 30, 2015
    Posts:
    37
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    Pretty much. But also depending how do you won't to affect behaviours of game instance. I.e. NPCs.

    You could make your self easier, and write game moddable, with assemblies dlls. Basically you compile dlls and then allow other modders to replace them if they need to.

    If you let's say want to do lua way, you are in double work area. Let's say you want NPC move from A to B, based on other NPC getting close to the tree.

    So how do you marry both Unity engine and lua?

    You need expose functions to navigate to the point. You need validate, if the way is path able. Now you do this C# or lua side. Is up to you. But Unity has ready solutions for that.

    Then you need check for events. So you need to monitor them. Like other NPCs, positions and states, and nearby objecects and npc.

    You need functions back and forth between lua and C#. Debugging will be awful. Lua can crash Unity withoth stack trace. You probably will be into the spot of writing major login in lua, and use rendering side on Unity.

    I don't know if you have or not, but based on how you write your questions, you didn't made any bigger Unity project.

    Meaning, you don't know yet, what you may need. And you will need to know a lot, before jumping into creating moddable game. Otherwise you either trat project as fun and learning exercise withouth obligations, or you get yourself burnout out of frustration and lack of progress.

    In my view, you are better of stick for now with C# and learn data driven design.

    You will be plenty occupied with this alone :)
     
  10. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,875
    @JoeStrout has miniscript I believe , I would look into that

    EDIT: ah I see @neginfinity beat me to the suggestion :p
     
    JoeStrout and neginfinity like this.
  11. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,019
    You could also write your own bytecode script compiler.

    When it comes to Lua, as lovely as it is, I still find it difficult to marry it with a C# project because it ultimately requires a DLL that contains the compiled C code. And then hooking up methods to Lua and managing object lifetime is cumbersome and error prone unless you use one of the Lua binding libraries - the one that I used to prefer is written in C++, which would make the C# setup even funkier.

    Lifetime is the major pain in the butt. You free an object on the C# side so you have to let it go on the Lua side and the Lua scripts need to still work even with an object becoming nil. The other way around could cause memory leaks as you release an object on the C# side but some Lua script still holds on to it in a list indefinitely. There is no good way to monitor this behaviour, hence my reliance on an established and proven binding library that took good care of that lifetime behaviour.

    And be aware that hot-loading code/scripts is not allowed on all platforms, specifically the AOT platforms iOS and UWP forbid it.
     
  12. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,124
    CodeSmile likes this.
  13. kaxifakl

    kaxifakl

    Joined:
    Aug 8, 2022
    Posts:
    1
    You can still use c# and update script by HybridCLR.
     
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,841
    In case you do want to consider MiniScript, you'll find it at https://miniscript.org. And you might find this academic paper comparing MiniScript to Lua and Python to be helpful. MiniScript has an active user community and we're always happy to help, so feel free to join our Discord server (link at the home page above) and ask any questions you may have!