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

Visual Studio closes all opened scripts when creating new script in Unity

Discussion in 'Editor & General Support' started by PixelPockets, Apr 29, 2022.

  1. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143
    I don't know if this is a Visual Studio issue, or a Unity issue.

    How can I stop this from happening?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    The act of creating a new script causes Unity to re-execute the "Assets -> Open C# Step," which wipes out the
    .csproj
    and
    .sln
    files and regenerates them.

    AFAIK there's no way to both have this very-handy functionality and suppress it from triggering each time you add a new script.

    When I pop back to Unity to create a new script, I just always save all scripts in Visual Studio, or even just close VS completely.
     
  3. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143

    Well then let me ask you this -

    Is there any way to batch open the "recent files" list in Visual Studio? Also, is there a way to increase that list, as it seems to be limited to 10 (I typically have a lot more than that open at any given time)?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    These questions both seem better suited to google. I know I have tweaked the count of recent files, but the last time I even used recent files in VS was 1999 or 2000.

    Do you know about Command-Period (or Ctrl-period) to search stuff in VS? it's SUPER-powerful. It's that little search box in the upper right. That is almost 100% of how I navigate in VS. It finds methods, variables, filenames, classes, etc.
     
  5. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143
    Point taken

    That doesn't mean other people don't use it.

    No, I didn't know that, so thanks for the heads up ;-)

    OH, and quit stalkin me dude.. (that was just a joke)
     
    Kurt-Dekker likes this.
  6. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143

    I found this earlier, and was curious if this is related to what I am experiencing -

    https://docs.microsoft.com/en-us/vi...oads-or-visual-studio-losing-all-open-windows

    I read the article, and verified that I do have the proper targeting packs installed.

    Something else that bothers me is that this is a recent development. I don't remember VS closing all my tabs when I first started working with Unity a few months ago. That article seems to suggest that this isn't intended behavior..

    I'm on 2021.2.16f1, if that makes any difference.


    EDIT: This does not happen in VS 2019. I'm currently using VS2022 preview, but ran a test in 2019.
     
    Last edited: Apr 30, 2022
  7. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    +1 for it not happening in VS2019.
    This is very frustrating, especially in the early stages of a project, where I'm working on a script and find that, oh, I need to make another one. Oop, have to re-open them all again. Ah, need another script. Sigh
     
    theMasky likes this.
  8. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143
    Try using the full release of VS 2022, instead of the preview. That seems to function correctly, at least for me.
     
  9. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    I am using the full release. v17.2.0
    I did try the preview, just to see if maybe that worked for me, for some reason. It did not. Reverting back to full release.

    Edit: I've updated packages, restarted, re-created csproj and sln files, it's still closing scripts when I make a new one
     
    Last edited: May 14, 2022
    Brightori likes this.
  10. Brightori

    Brightori

    Joined:
    Sep 15, 2017
    Posts:
    64
    have same problem, now way to fix it?
     
  11. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    This seems to be a Visual Studio issue. This is happening to me since updating Visual studio, while I haven't changed Unity versions on any of my projects. This includes projects across both Unity 2020 and 2021.

    So I'm guessing this is something in the recent update causing this. 17.2 seems a bit shonky overall, as I've had other various features of it crash or not work on me as well.

    Hopefully a future update fixes this.
     
  12. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    My fix was to just go back to VS 2019
     
  13. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    There is a Visual Studio 2022 v17.2.1. Was wondering if the patch update fixes this issue? (The 17.2.32516 is referred to as 17.2.1 patch release build number).

     
    Last edited: May 18, 2022
  14. Weebow

    Weebow

    Joined:
    Oct 24, 2018
    Posts:
    1
    I just updated and unfortunately, the issue still persists.
     
    Brightori likes this.
  15. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Same news here. It's infuriating. Back to Visual Studio 2019.
     
  16. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Ugh, I just uninstalled VS 2019, thinking there is no need to use it when VS 2022 is out.
     
  17. NingWuZ

    NingWuZ

    Joined:
    Oct 27, 2020
    Posts:
    1
    Same Here.
     
  18. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    152
    Last edited: May 22, 2022
    Brightori likes this.
  19. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
  20. Alexaroth

    Alexaroth

    Joined:
    Feb 4, 2019
    Posts:
    29
    bump, same issue for me too
     
  21. theMasky

    theMasky

    Joined:
    May 8, 2015
    Posts:
    124
    Yep, this is only happening in VS2022. I did not happen back in VS2019.
     
  22. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    I recommend the free "Workspace Manager" VS extension as a little helper for people who need to keep working with VS2022. With it you can save all opened documents and load them conveniently.
     
  23. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    152
    A fix for this issue has been internally implemented and is being prepared for release. We'll update you once it becomes available for download.
     
  24. theMasky

    theMasky

    Joined:
    May 8, 2015
    Posts:
    124
    Thanks!
     
  25. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    152
    Fixed in version 17.2.3.

    A fix for this issue has been released! Install the most recent release from https://visualstudio.microsoft.com/downloads/.

    Thank you for providing valuable feedback which has helped improve the product.
     
  26. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    It works again! Thank you and also thank you OP for posting this thread!
     
  27. mpbMKE

    mpbMKE

    Joined:
    Aug 13, 2019
    Posts:
    3
    Awesome, thanks!
     
    Jamisco likes this.
  28. Aleksei-Laser

    Aleksei-Laser

    Joined:
    Apr 4, 2014
    Posts:
    7
    Hello. It is reproduced with Unity 2021.3.14f1 and Visual Studio 17.4.1
    It happens when existing cs file is duplicated within Unity with Ctrl+D keys, but not 100%.
     
  29. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    @sailro Another repro step for this: in Visual Studio, save an opened script as "Save as...". Unity compiles, and all files are reverted.
    Another repro: rename the class name, and specify you'd like rename the file as well.

    These are a pretty frequent use case, quite annoying. Repros with 17.4.4