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
1
Question by Wrymnn · Jan 20, 2015 at 01:05 PM · runtimechangedebug

Change code at runtime

Does unity have some kind of debug tool? Or when I run the game, change some code, and the game will continue with changes I made WITHOUT resetting all variables and breaking the game.

I know it has to be compiled first, but I`m just asking :D

Visual Studio preferably.

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

3 Replies

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

Answer by Denvery · Jan 20, 2015 at 01:34 PM

May be this tool will help you? http://unityvs.com/ we use it.

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 Wrymnn · Jan 20, 2015 at 02:39 PM 1
Share

Hehe thanks :) I know but won`t it reset all my variables if I press ctrl+s? That is the only problem of changing code at runtime, saving it and watching the game break since nothing is initialized.

avatar image
2

Answer by winxalex · Dec 05, 2018 at 01:35 PM

@Wrymnn As far as I know unity doesn't have such tool. But unity is build to work that way. Meaning you can change the code while runtime, save(Ctrl+s), wait to compile, and then unity will reinit variables. Unity will reinit ONLY serialized variables, marked as PUBLIC or [SerializeField]. Unity won't init runtime created and init variables or objects. So you need to have custom code which will handle DidReloadScript callback and init those. See in practices urself.

  [UnityEditor.Callbacks.DidReloadScripts]
         private static void OnScriptsReloaded() {
 
           //custom init here
         }

 


Comment
Add comment · Show 3 · 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 kulpajj · Jul 12, 2020 at 06:15 AM 0
Share

I think this is the Best Answer.

It didn't solve the issue yet but it shed the most light on the subject.

In testing this, I found that winxalex's code shouldn't be added to the $$anonymous$$onoBehavior script being edited at runtime. Ins$$anonymous$$d, this code needed to be its own separate script, itself a generic script, not a $$anonymous$$onoBehavior. This generic script then gets a reference to the $$anonymous$$onoBehavior script being edited at runtime. This generic script also includes winxalex's code OnScriptsReloaded(). Inside this method I could then make use of the reference to the $$anonymous$$onoBehavior script being edited at runtime.

Unfortunately, however, in a complex project, Unity still throws NullReferenceExceptions for scripts unrelated to what I'm editing at runtime. I don't understand why or what the solution is.

Thus far, winxalex's statement seems unfortunately true: "As far as I know unity doesn't have such tool." I'll not be attempting to edit my scripts at runtime unless I learn more about what I could do better here to allow runtime editing of scripts.

avatar image winxalex kulpajj · Jul 12, 2020 at 08:28 PM 0
Share

Exactly OnScriptReload can be for example on some EditorWindow script or probably script with Init On Load, then when event happen you can do GetComponents() and on them call for example function On$$anonymous$$y$$anonymous$$onoTypeWhenScriptReloaded. Other way is to use heavy reflection as LIVITY does when you change function of the class with other version....

avatar image kulpajj winxalex · Jul 14, 2020 at 07:44 PM 0
Share

Thanks, I hadn't heard of Livity until now. I just read the thread on it - back in 2013 it looked like the future had arrived early! But by the end of the thread, seems like for me it would be best to hold off until something like this is still regularly supported. https://forum.unity.com/threads/livity-the-live-coding-tool-for-unity.195537/page-7

$$anonymous$$y current project has undergone quite a bit of development already and I don't want to introduce this based on comments in the thread. This would be an incredible workflow to have someday.

avatar image
0

Answer by logicandchaos · Jul 12, 2020 at 02:58 PM

You can use scriptableObjects to have is so you can change data, swap out data and functions all while game is running and changes are persistent, but I don't think you can change the code live right now, I think that is something they are working on tho.

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 winxalex · Jul 12, 2020 at 08:30 PM 0
Share

Check for LIVITY :)

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

29 People are following this question.

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

Related Questions

Changing a second objects material on trigger 0 Answers

Change 'Color Mask' Property At Runtime 1 Answer

How to dynamically change the shape of a mesh during runtime? 1 Answer

[Android] Bad Rendering for whole Canvas UI. Change sprite image run-time after clicked 0 Answers

Is it possible to change the Frame Over Time property of a ParticleEmitter at runtime? 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