Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by oren_danniel · Sep 12, 2016 at 06:31 PM · runtimedllcompilepythonruntime compile

unity allow player to script a object or compile and run a code in runtime

Hi!

I am working on a game in which the player needs to code a cube, now I have asked this question before but I didn't get a clear answer, I have tried many approaches such as: using lua moon sharp(but I couldn't figure out how to tell the object to goForward() for exp), compiling the script(C#) on the fly(but couldn't figure out what to do with the assembly, I don't even know what an assembly is). I have also tried codeDom, and I have a script that compiles string but I don't know what to do with it.

so can somebody tell what is the simplest way to let a player write his own code(C# or lua or python) and then compiling it and applying it to a game Object (for now lets assume that there are no error or security problems) .

BTW I have already made a program that allow the player to write his source code and save it, and I do know how to take the source code and turn it in to a string.

It would be great if you will give a clear and detailed answer. and if can someone explain to me what is dll it would be great too

thanks for the help

Comment
Add comment · Show 4
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 iabulko · Sep 12, 2016 at 07:31 PM 0
Share

I do not want to be rude but you are trying to write a compiler without a basic program$$anonymous$$g knowledge. That's not the right way to do this. First, learn a bit more and then try to do such a hard task ;)

avatar image oren_danniel iabulko · Sep 13, 2016 at 11:37 AM 0
Share

I have actually read every article about the topic and to I am asking you for a simple answer its because English is not my native language

avatar image toddisarockstar · Sep 13, 2016 at 05:12 AM 0
Share

you generally wouldn't want to allow a user to write ACTUAL code in your game for security and safety purposes. Also users would crash there own games. so i can assure Unity wouldn't have a formal option for it.

if you where really persistent and if you had a whole lot of time, you could take your users input and have your real code attempt to read the users string and try make scene of it to let them change some basic stuff about an object.

but you can't import/compile actual scripts on the fly.

avatar image AurimasBlazulionis toddisarockstar · Sep 13, 2016 at 05:57 AM 0
Share

Wrong, you can import actual scripts on the fly. This is the way to do it. It only does not work on iOS.

1 Reply

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

Answer by AurimasBlazulionis · Sep 13, 2016 at 06:08 AM

I have not tried any of this, but this blog post seems to explain how to do this really well. You will just need to rewrite the code so that it loads not from the URL, but from the file instead.

The only problem I see is compiling actual code. This looks like an excelent post.

Now what is dll? Windows calls it Aaplication Extension. Dll is a compiled library (any kind), which can be loaded to application to make use of. In dlls you can store scripts or some low level code. Usually, unity builds few dlls for all of your scripts, but you can add more at any time you want. This is very useful when you need to update your game so people would not need to redownload everything again or when you want to do things what unity engine can not provide by itself.

Note: dlls usually have to be compiled for each operating system separately.

Comment
Add comment · Show 6 · 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 oren_danniel · Sep 13, 2016 at 11:43 AM 0
Share

I have seen that article before but, I missed something in there. And I found what was missing and I think I have just got clear answer, I will do some testing and I will let you know how it goes.

thanks you very much

and thanks about the explanation on the dll it was useful:)

avatar image oren_danniel · Sep 19, 2016 at 03:15 PM 0
Share

so after a lot of testing and reading I couldn't figure out how to solve a problem with the script in the article(it delegates a static function only and transform can not be in a static function) but after thinking about the idea of C# compiling at run time again I came to the conclusion that it may not be the smartest idea letting the player use C#.

So after doing some research about moonsharp again I figure out how to run lua script but I can only run return value and I don't know how to tell lua to do things like forward() GetEnemyDistance() Turn(), is there a DLL for those thing? Do I need to make my own DLL?if so, how?

avatar image AurimasBlazulionis oren_danniel · Sep 19, 2016 at 05:53 PM 0
Share

All you need is a value. As I am not familiar on lua script, you could try storing a returned value to a variable in c# and then in update loop check for changes.

On the other hand, in c# code, when you have a static function, you can also have a static variable pointing to a transform you want to edit. So it would be declared as public static Transform myTransform;. Then, you just assign YourClassName.myTransform to your object and now you can move it from script.

avatar image AurimasBlazulionis oren_danniel · Sep 19, 2016 at 06:13 PM 0
Share

But have you seen this? It states to include everything you need. It says it allows to read and write lua variables, call .net functions etc. It is really worth checking out, the example scene. It is licensed under $$anonymous$$IT so you can do almost whatever you want with it.

Check TestBehaviour. It looks like you can call Debug.Log, GetComponent and much more.

However, it seems that the library does not work under linux so I could not test it.

Also, it allows for the full access to unity api so wouldn't it be just simplier to get back to c# compiling and figuring things out of static variables, because it looks like to be the easiest way for multiplatform (apart iOS, which is again bad). I guess it is a tough decision, the lua one might support all platforms even iOS, but you will have to compile the library yourself (I do not know how).

avatar image oren_danniel AurimasBlazulionis · Sep 19, 2016 at 06:28 PM 0
Share

thanks a lot I will look in to your idea of calling value in an update loop. its a really good idea

and I will check out the link.

many thanks :)

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Runtime Python interpreter 0 Answers

Unity trying to build a referenced DLL 0 Answers

Server side c# scripts loads at runtime 0 Answers

c# to compile xml string as code during runtime 1 Answer

Reference class in normal c# script from within a (soon to be) dll script? 0 Answers


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