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. Dismiss Notice

Bug Unity keeps reverting Visual Studio code changes (AKA the most frustrating thing ever)

Discussion in 'Scripting' started by TheAvolition, Jun 25, 2023.

  1. TheAvolition

    TheAvolition

    Joined:
    Jun 25, 2023
    Posts:
    5
    I'm using Cesium for Unity. I want to change a couple minor things about how the DynamicCamera (CesiumCameraController) works. When I change anything in CesiumCameraController.cs and hit save, a couple seconds later the code just reverts. I'm positive this is Unity, as I tested by closing Unity and making a bunch of changes. Sure enough, as soon as I opened the project in Unity again, *poof*. All changes were gone.

    How do I stop this from happening? It's maddening.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    Is Cesium delivered as a package? Packages are immutable and will get restored.

    You can "bake" the package into your project and remove it from Packages/manifest.json if you want to tinker.
     
  3. TheAvolition

    TheAvolition

    Joined:
    Jun 25, 2023
    Posts:
    5
    So it is intended? Probably the worst UX I've ever seen. "Oh, we'll just keep overwriting that file in the background without telling the user".
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    If that is what is happening, it is telling you and telling you exactly why. Did you look in the console?

    Have you first determined that it is in a package?

    Pretty much any package manager works this way.

    Otherwise, how could you ever know that the packages were legitimate?

    By design packages are not source controlled, so you would never see changes in them.

    You are using source control, correct?
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,082
    Yes, the intention is that the packages are the responsibility of the editor not the user. You can override this by moving the package out of the package cache (ProjectFolder/Library/PackageCache) into the packages folder (ProjectFolder/Packages) but once you've done that it's now your responsibility to maintain the proper version.

    I don't recall having to modify the manifest in the past that might be new or it might just be for built-in packages.

    https://support.unity.com/hc/en-us/articles/9113460764052-How-can-I-modify-built-in-packages-
     
    Last edited: Jun 25, 2023
  6. TheAvolition

    TheAvolition

    Joined:
    Jun 25, 2023
    Posts:
    5
    It is a package. There is nothing in the console, either Unity or VS. Thanks for the help.
     
  7. TheAvolition

    TheAvolition

    Joined:
    Jun 25, 2023
    Posts:
    5
    So unity defaults to "clear on build" and that is what was happening, so I never saw any error. But, here it is:


    The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
    Packages/com.cesium.unity/Runtime/CesiumCameraController.cs

    UnityEditor.AssetDatabase:Refresh ()
    Microsoft.Unity.VisualStudio.Editor.VisualStudioIntegration/<>c__DisplayClass8_0:<RunOnceOnUpdate>b__0 () (at Library/PackageCache/com.unity.ide.visualstudio@2.0.17/Editor/VisualStudioIntegration.cs:100)
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()​

    All I was doing was clicking on a component and hitting "Edit script" on the sample project. So, by default, I had no way of knowing this was not okay.
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    I get this in my Unity console window:

    The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered: Packages/com.unity.ugui/Runtime/UI/Core/ColorBlock.cs


    Make sure your log console selector buttons are enabled. See this graphic:

    https://forum.unity.com/threads/cant-add-script-component.632746/#post-4239121

    https://forum.unity.com/threads/update-function-not-working.953477/#post-6215873

    EDIT: I guess you replied while I was typing!

    Yeah, I suppose another way would be to simply fail the build if the package is modified... it's absolutely mission critical to never ship with package tinkerings (madness could ensue), but that at least would give you a chance to go in, fish your changes out, put them somewhere else, revert, bake the package, etc.

    I just wish there was a single button to bake-and-remove-package. :)