Runtime C# compilation - interfaces

Hey guys.

As far as I know, you can compile C# at runtime via something like this:
C# Runtime Compilation

The whole idea is, that I want to make a modable game, where players are able to code behavior in a part of the game (level editor or toolset or something), compile it, release it over the internet and then share it with other people.

To make it simple to change the behavior or add new behavior, I would like to set up some interfaces, that the modder can implement, which would in theory be interchangeable with my own implementation.

Anyway, my question is, if I code the interface in unity, outside of the running game, would it be possible for the modder to use my interface and my classes, without letting them change them?

Would it also be possible to call classes and methods that I have created in unity, that the modders theoretically arent able to see or change?

I hope it makes sense. Thanks a lot for your time.


As far as I know, if you allow the players to run c# code by using reflection, it is really a matter for the experts to keep everything stable and secure. Also, you’ll not be able to run your game on iOS (if this was ever your intention).

You can try to integrate your game with one scripting language such as Lua or Python. They are really fast, and since it is up to you to “tie” methods and classes between your game and users code, you can make a game modable without the user needing to have a deep understanding on the game workings.

If you want the users to definitely change the binary code of your game, consider making it open source - this will make it easier for both developer and users.