Gametime scripting in Unity Games...

Hi all,

I need the ability to export a simple API to my game users and the ability for these users to enter simple scripts and have my Unity-based game run their script during gameplay… Can this be done?

I searched for an ‘eval’ or ‘exec’ statement but this Unity game runtime doesn’t appear to have the ability to JIT compile a string and execute some of my API functions.

My game doesn’t run in the WebPlayer so could not rely on calls such as Application.ExternalEval or Application.ExternalCall. (If such functionality were available in non-WebPlayer game builds I could save the day with that!

What are possible alternatives?

  • A way to JIT compile Mono code in game runtime.
  • An external library I can ship with my game to allow me to export an API and give game players scripting (Mono/C# prefered but other languages like Python a possibility)
  • Could I embed Internet Explorer in my game, export my API and export scripting through that?
  • Or maybe it’s something I’m overlooking on what the game runtime can do?

Thanks for any hint!! :slight_smile:

Dan

Unity does have eval, but only in Unityscript.

–Eric

theres 2 options off the top of my head.

  1. Theres a solution on the asset store to have real python scripting so users can mod your game. I dont know the name of the product, but I remember seeing it advertised on this board.
  2. write your own scripting language that’s specialized for what you need to happen in your game. If you need a full fledged programming language, then this prob isn’t the best option, lol.

Hi Eric5h5, thanks for that important hint with eval. This page contains a code sample using this technique that I was to make work so I should be OK.

There is however another interesting approach based on the mcs Mono compiler. Has anyone been able to included this in a game runtime and make it work during gameplay? (I could not find the dependencies / traces of its code)

Kablammyman: thanks for that heads up on the python interpreter… will keep in mind, but so far UnityScript’s eval seem to be able to do the job! :slight_smile:

Cheers!