You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.4.5 Apps distributed via the Mac App Store have some additional requirements to keep in mind:
(iv) They may not download or install standalone apps, kexts, additional code, or resources to add functionality or significantly change the app from what we see during the review process.
2.5 Software Requirements
2.5.2 Apps should be self-contained in their bundles, and may not read or write data outside the designated container area, nor may they download, install, or execute code which introduces or changes features or functionality of the app, including other apps.
Although rules have been relaxed compared to earlier versions, I think runtime loaded scripts would violate Apple guidelines ("execute code which introduces or changes features").
Thus, I will not bother with this on iOS.
Besides, Unity can also only compile for iOS using IL2CPP, i.e. the C# code is compiled to C++ code, which is then compiled to native machine instructions for iOS.
This may be good for performance and security, but it makes dynamic language features unavailable.
Suggested solution/s
This article covers runtime loaded scripts in the context of a Unity game.
There are three basic approaches to adding scripting to Unity games:
Loading in executable code, native or .NET. This is traditionally difficult because modders don’t have good tools to do this. But – this is changing.
Embedding an existing scripting language like Lua in the game. This is easy for modders, but a lot of work for the developers to support, and performance is considerably slower.
Writing a custom scripting language and building an evaluator in the game. This is probably the most work, since it means creating a new language, parser, evaluator, etc., but it lets developers create a domain-specific language that’s tailored precisely to the needs of the game.
I made a prototype for the first two approaches
compile and run C# code at runtime (as described by the article)
Runtime loaded C#. I successfully tested it on Windows and Android.
This only works on Android with the Mono scripting backend.
However, to build for ARM64 and Google Play, the IL2CPP scripting backend is required.
But IL2CPP compiles ahead-of-time (AOT) and does not support anything in the System.Reflection.Emit namespace (see IL2CPP restrictions).
Thus, runtime loaded C# using Mono.CSharp.dll as explained in the article above is not possible.
Compilation may still work but at runtime, there will be an error message.
In conclusion, TypeScript / JavaScript with Jint may be the better approach when targeting desktop as well as mobile. OneJS integrates it very well in Unity. It also uses including React for UI dev. But it is only available as a paid asset on the Unity Asset Store.
BTW: https://github.com/SoapCode/UCompile is a lib that takes the same approach, i.e., compile with Mono.Csharp.Evaluator. But this does not work with IL2CPP (Android / iOS)
Problem or question to be solved
Runtime loaded scripts would be a powerful mechanism to let users add / change features.
For example, it could be used to
You get the idea.
The Steam Workshop might make for a good way to share user defined scripts.
Requriements
The following is required for this to work well:
iOS and tvOS restrictions
Apple is bitchy about runtime loaded code: https://developer.apple.com/app-store/review/guidelines/
Although rules have been relaxed compared to earlier versions, I think runtime loaded scripts would violate Apple guidelines ("execute code which introduces or changes features").
Thus, I will not bother with this on iOS.
Besides, Unity can also only compile for iOS using IL2CPP, i.e. the C# code is compiled to C++ code, which is then compiled to native machine instructions for iOS.
This may be good for performance and security, but it makes dynamic language features unavailable.
Suggested solution/s
This article covers runtime loaded scripts in the context of a Unity game.
I made a prototype for the first two approaches
Runtime loaded C#
This works surprisingly well! I successfully tested it on Windows and Android.
Pros
Cons
Runtime loaded JavaScript / TypeScript
Why JavaScript (and not Python, Ruby, Lua, etc.)
So far, the same is true for Python. But
Finally, Jint is a quality JavaScript interpreter in pure C# that
My approach
Pros
Cons
Your opinion on the topic
Both approaches can meet the requirements.
But I would use the C# approach.
The text was updated successfully, but these errors were encountered: