Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by flexrails · Nov 18, 2009 at 12:23 AM · runtimeinterpret

interpret unityscript at runtime?

is it possible for unity to interpret a unityscript at runtime, i. e. could i enter unityscript commands in a gui and execute that at runtime?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Justin D'Arcangelo · Apr 11, 2010 at 07:23 AM

Actually, this can be done when using UnityScript since it is based off of the Microsoft JScript language in the .NET Framework. It is, however, NOT recommended for performance and security reasons. If you still want to do this for something like an in-game debugging console, you can use the eval() function. For further reference, please see the .NET documentation on JScript's implementation of the eval() function here: http://msdn.microsoft.com/en-us/library/b51a45x6(VS.80).aspx

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lucas Meijer 1 ♦♦ · Apr 11, 2010 at 12:17 PM 1
Share

you can indeed do this using eval(), however our Javascript implementation is not "based off" the microsoft jscript language.

avatar image
3

Answer by Eric5h5 · Apr 11, 2010 at 07:44 AM

I'd rather add this as a comment to Justin's answer because it's correct, but I can't do code formatting that way, and I wanted to add a little example:

import UnityEngine.GUILayout; private var exeText = ""; private var run = false;

function OnGUI () { exeText = TextField(exeText, Width(600)); if (Button("Execute", Width(60))) { run = true; } if (run) { eval(exeText); } }

Put some GUI code in the text field, click execute, and see what happens, like this maybe:

for (i = 1; i <= 10; i++) Label(i.ToString());

Of course, it's trivially easy to crash Unity that way by entering junk instead of valid code.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Oct 18, 2013 at 07:17 AM 0
Share

@Eric5h5 Um... won't your OnGUI never stop running the code?

avatar image
1

Answer by Ashkan_gc · Apr 11, 2010 at 11:23 AM

actually there are 3 ways to do this. 1 using Eval as Erric5h5 said. (i did not test it) 2 mono has a class for compiling C# code at runtime. i think lucas meijer made a ingame console debugger with it. 3 when unity releases 3.0 and updates to newer version of mono (they will upgrade to 2.6 just like iphone but even 2.2 is enough) you can use DLR and ironpython or ironRuby or your own scripting language to run scripts at runtime.

it's the best way to make patches easily

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

Answer by NickolasTheGreek · May 31, 2012 at 10:31 AM

You can try this: http://u3d.as/content/nick-aliferopoulos/leda-runtime-scripting-language/2ZP

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-3

Answer by Brian-Kehrer · Nov 18, 2009 at 05:32 AM

Nope. The 'script' in unity is actually compiled to an intermediate language when you build your app, and then compiled to machine code at runtime, using the JIT compiler.

EDIT: Oops. This is wrong. Sorry guys.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brian-Kehrer · Nov 18, 2009 at 05:22 PM 0
Share

Additionally, this is part of the reason the language is so powerful and fast. It is not simply a scripting language, but built on $$anonymous$$ono 's open source implementation of C#. $$anonymous$$ost runtime scripting languages must run through some sort of interpreter or emulator, and end up being much slower.

avatar image Lucas Meijer 1 ♦♦ · Apr 11, 2010 at 12:16 PM 0
Share

downvote explanation: It is possible to do this, see other answers

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Interpreted Scripting 1 Answer

Text Mesh not updating during run time? 2 Answers

Using replacement shader at runtime? 1 Answer

How to Serialize Scriptable Object at Runtime? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges