Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Virtual Studio reverting code periodically?

Discussion in 'Code Editors & IDEs' started by BoxTurtle_Games, Jul 23, 2023.

  1. BoxTurtle_Games

    BoxTurtle_Games

    Joined:
    May 6, 2022
    Posts:
    31
    First off ignore the typo in the title, it is "visual studio" as @CodeSmile pointed out

    I use Visual Studio when writing scripts, but recently it has been saving changes to my scripts, and allowing me to run the edited script in unity, but then immediately reverting the script to its original state (even before the previous save) when I try to save it a different time. I am not very tech-savvy so I have no idea what is happening, and could get no clear answer out of previous forum posts about the issue. Here is a video of the issue, in case someone has a clue how to diagnose this.


    As you can see, the lines of code that I commented out as an example have reverted to what they were before I tried to save (I garantee I pressed Command+S before returning to unity). This applies to other scripts as well.

    Hope someone can point me in the right direction.

    Thanks, -K:)
     
    Last edited: Jul 23, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,360
    VSCode is not supported!

    Please use Visual Studio Community which you can install in the correct version through the Unity Hub. Select the editor version you are using, click on the cog icon and Add Modules. VS is the topmost item.

    Never heard of that one. :D
     
  3. BoxTurtle_Games

    BoxTurtle_Games

    Joined:
    May 6, 2022
    Posts:
    31
    I have been using visual studio fine without any issues for about a year paired with unity now, do you know what caused it to suddenly be unsupported? (also if you are going off the video title, the title is probably wrong, it should just be "issue in Visual studio," in case VS code is something different from visual studio)

    One more thing, where might I find this in Unity Hub? I can only find downloads solely pertaining to other versions of unity.

    Thanks for pointing out the typo by the way
     
    Last edited: Jul 23, 2023
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,360
    Got it! Yes, I thought with the video title and the barebones looking UI that it was VSCode (didn't watch the video fullscreen). But I see you're working on a Mac.

    Visual Studio Code (VSCode) is essentially a text editor with plugins that enable it to work as an IDE (although hardly for professional use).
    Visual Studio Community is the free version of Visual Studio (VS).


    Anyhow, the issue you're seeing is to be expected. You are editing a script inside a unity package (com.unity.xr.interaction.toolkit). Unity packages are read-only, any changes to it will be restored by the editor. You're probably supposed to make a subclass of the script or subscribe to its events.
     
  5. BoxTurtle_Games

    BoxTurtle_Games

    Joined:
    May 6, 2022
    Posts:
    31
    I started using unity recently, and have no idea how to do either of those. If its not too much of a hassle, do you mind either explaining the concept of making subclasses of a script or "subscribing to its events", or directing me to a resource that can explain them in relatively simple terms? All of the resources that I found use terms I am not familiar with.
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,360
    Well subclassing is simply taking that class and inherit from it in your own script, something like:

    Code (CSharp):
    1. public class MyControllerDriver : CharacterControllerDriver
    2. {
    3. }
    But I don't know this package and whether that's how it's supposed to be used. Usually you'd get that info from the manual or a tutorial for this particular package.
     
    BoxTurtle_Games likes this.