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

Resolved How do I load scripts at a directory during runtime?

Discussion in 'Scripting' started by Chazzwazzler, Dec 29, 2020.

  1. Chazzwazzler

    Chazzwazzler

    Joined:
    May 2, 2018
    Posts:
    35
    I want to make my game moddable by letting players put scripts in a folder in the game files, but I'm not sure how I can load those files into the game in some form. How do I do this?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    There's no facility to compile scripts in your built game engine. You can always use an interpreted language... I have used MoonSharpLUA and it's pretty slick in Unity.

    As for other ways, check on the mods forum. We here don't do much modding because we have the Unity editor and our project source code!
     
    Chazzwazzler likes this.
  3. lyrapuff

    lyrapuff

    Joined:
    Oct 23, 2019
    Posts:
    7
    Actually you can just load Assemblies from DLL files at runtime, with no need in lua. Check on the c# reflection to get more information.
     
    Chazzwazzler and VolodymyrBS like this.
  4. AwesomeAlexx

    AwesomeAlexx

    Joined:
    Jan 30, 2016
    Posts:
    18
    Hello @Chazzwazzler
    You can use an amazing tool on the asset store : Roslyn C# - Runtime Compiler

    I'm currently using it and works very welll.
    As @lyrapuff said it works with DLL and assemblies.

    The idea is Unity works with compiled scripts so if you try adding a non compiled one it can't work Roslyn allow you to compile it on an assembly and then use it.