Search Unity

Bug "Play" Broken, "Build and Run" still works

Discussion in 'Editor & General Support' started by DrLulz, Apr 3, 2023.

  1. DrLulz

    DrLulz

    Joined:
    Nov 14, 2022
    Posts:
    11
    I have a problem with my project (unfortunately i don't have a rollback version).

    I was messing around with the animator for UI elements and now my project won't play in the editor anymore.
    i didn't save the changes to the editor and i (as far as i can tell) changed back the few lines of code i had changed for to call the animation.

    i'm also not getting any error messages from the editor.

    now when i try to play the project in the editor it loads in the Textmesh interface numbers it's receiving from the script and initiates the first enemy but doesn't do anything else.
    the enemy doesn't move using navmesh and the player doesn't react to user inputs.

    HOWEVER when i "build and run" the game it still works. so the project itself doesn't appear to be broken.
    i can also still make changes to the script which are present when i "build and run"

    when i tried making a copy of the project and loading the copy and it still doesn't work but other projects do play so it's not the editor itself that is broken.

    since i can still "build and run" i technically have a workaround but i really don't want to have to do that to test every little change.

    please help.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    There's a few random ideas in here to try:

    Lost progress / project / work / stuff disappeared in Unity.

    This article is to help you when you have lost significant progress or work in your Unity project.

    It is designed to give you avenues of discovery and investigation.

    It is NOT a guarantee of restoring your lost work. It is NOT a substitute for proper IT / Data security procedures.

    To decide which parts are applicable to you, look for major bolded headings.

    EVERYTHING IS GONE, YOU CANNOT OPEN THE PROJECT

    Your project probably is still on your computer. Try a computer-wide search for some unique filenames that you know are in the project you think is gone.

    To start your search, one common file to all Unity projects is named
    ProjectSettings.asset


    Some things that might have happened:

    - you are not opening the project that you think you are
    - you are in the correct project but not opening the same scene you had open before
    - you dragged the project (or part of it) into the trash (intentionally or inadvertently)
    - you moved the project (or part of it) somewhere else (intentionally or inadvertently)
    - an overly-aggressive antivirus solution quarantined it because it saw code being compiled in there
    - you're using a directory sync like OneDrive or Dropbox... NEVER USE THESE SERVICES WITH UNITY!
    - something else??

    As I said, it's probably still all on your system to be found if you look in the right places.

    A typical Unity project will have at a minimum the following folders:

    Assets\
    ProjectSettings\
    Packages\


    EVERYTHING IS PRESENT BUT MY SCENE WINDOW IS BLANK

    Close Unity and make a full project backup RIGHT NOW. Do not do ANYTHING else until you back it up 100%.

    Ideally copy that backup to another computer, or back it up to another external hard drive entirely. This is just basic data processing best practices during data recovery operations.

    If you can see all the files and folders of your project, make sure you are opening the scene file you were working in.

    Once you have opened the scene, look in the hierarchy window, select an object and move the mouse over the Scene window and press F to focus that object.

    Additional notes:

    - ALWAYS use proper industrial grade source control (see below)
    - NEVER use Dropbox or any file sync mechanism in Unity.
    - NEVER move files within your project, except by doing it within Unity
    - ALWAYS be sure you are fully backed up before upgrading Unity

    SCRIPTS OR ASSETS ARE MISSING OR BLANK

    Some info about Missing script warnings, broken prefabs, GUIDs, renaming GUIDs, etc:

    https://forum.unity.com/threads/problem-with-git-and-missing-scripts.1090876/#post-7024801
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6487297
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6488230

    EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile, and hence why the metafiles ALWAYS MUST be source-controlled.

    When Renaming: It is super-easy to inadvertently change the GUID by renaming outside of Unity. Don't do that. Instead:

    - close Visual Studio (important!)
    - rename the file(s) in Unity
    - in Unity do Assets -> Open C# Project to reopen Visual Studio
    - now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!

    If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process. Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.

    UNITY CRASHES / FREEZES WHEN I OPEN MY PROJECT

    You must isolate if there is something wrong with your Unity installation, something wrong with your project, or perhaps just a corrupted import or asset database.

    First, ALWAYS back your project up. Then try deleting the
    Library/
    and
    Temp/
    folders that are within your project, the directories that are peers to the
    Assets
    and
    ProjectSettings
    folders.

    If that doesn't work it is time to bisect. Make a new empty project and get Unity to open that. If you cannot then it is time to fix your Unity installation, either by fully reinstalling or verifying it with the hub.

    Once you have an empty project open, begin copying over your project. Try the entire thing. If it crashes, try half of the project, then the other half, etc.

    As always, if you're using Windows, another "first thing to try" is to simply reboot the system. This often fixes typical Windows issues related to locked files and locked directories.

    ISSUES RELATED TO UPGRADING PROJECTS (eg, changing to a higher Unity version)

    Upgrading to a later version of Unity is a one-way process. Any project that has been updated should NEVER be reverted to an earlier version of Unity because this is expressly not supported by Unity. Doing so exposes your project to internal inconsistencies and breakage that may actually be impossible to repair.

    If you want to upgrade to a newer version of Unity, do not even consider it until you have placed your project fully under proper source control. This goes double or triple for non-LTS (Tech Stream) versions of Unity3D, which can be extremely unstable compared with LTS.

    Once you have source-controlled your project then you may attempt a Unity upgrade. Immediately after any attempted upgrade you should try to view as much of your project as possible, with a mind to looking for broken animations or materials or any other scripting errors or runtime issues.

    After an upgrade you should ALWAYS build to all targets you contemplate supporting: iOS and Android can be particularly finicky, and of course any third party libraries you use must also "play nice" with the new version of Unity. Since you didn't write the third party library, it is up to you to vet it against the new version to make sure it still works.

    If there are issues in your testing after upgrading Unity, ABANDON the upgrade, revert your project in source control and be back where you were pre-upgrade with the earlier version of Unity.

    Obviously the less you test after the upgrade the more chance you will have of an undiscovered critical issue.

    This risk of upgrading is entirely on you and must be considered whenever you contemplate a Unity version upgrade.

    Do not upgrade "just for fun" or you may become very unhappy.

    PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL

    I'm sorry you've had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

    Here is how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

    If you plan on joining the software industry, you will be required and expected to know how to use source control.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  3. DrLulz

    DrLulz

    Joined:
    Nov 14, 2022
    Posts:
    11
    Thank you for your reply

    unfortunately none of the suggestion seem to apply to my problem.

    the assets are still all there, i'm not getting any (new) error messages of anything missing, i can still see and manipulate the scene and i can even still work on the project by just always building it.

    what is broken is the "preview" function in unity.

    in theory i can still work on my project, i just need to always build every time i want to test something.

    however i don't really want to do that because i think it's a bad idea to continue working on a project that is partially broken.

    yes, i know i should have been using version control.

    i kept using "exporting package" which i thought was backing up versions but importing them does not seem to restore the game to the previous versions and the reason i wasn't using GIT is because GIT scarred me back in university.

    my brain is too small to figure it out.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,923
    Is it just this one scene that is broken? Can you make a new scene and see if that runs?

    It just sounds like you have introduced a few bugs that need to be work out.

    But in future, you should've been using version control as this would've been a 1 second fix.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,175
    If you haven't you should still delete the Library folder as mentioned in @Kurt-Dekker's post. Unity will make it again once you open the project. It's basically the equivalent to "turn it off and back on" for Unity. I've seen a ton of weird quirks resolved solely from that.
     
    spiney199 likes this.
  6. DrLulz

    DrLulz

    Joined:
    Nov 14, 2022
    Posts:
    11
    I would agree with the bugs but build and run still works.
    there are also no (new) error messages and i have no idea what i might have introduces as a bug.
    i don't even have a clue where to start searching for these bugs.

    i wasn't doing anything particularly involved at the time.
    all i did was sliding around UI elements using the animator and then writing something like 2 lines of code to call the bool to activate the animator which i have removed again.
    i have no idea why that would completely kill the project.
     
    Last edited: Apr 6, 2023
  7. DrLulz

    DrLulz

    Joined:
    Nov 14, 2022
    Posts:
    11
    thanks for the suggestion but i'm not sure how that was suppose to help.
    deleting the library folder just completely destroyed the project so i had to copy back the old backuped one.
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,175
    Unity's Library folder is a cache folder that is generated by the editor to increase performance. If deleting the folder broke everything that means the project was already broken before you deleted it. If you're having this problem you are most likely past being able to fix it. You need to recreate it.

    Install and set up version control while you're at it. With version control this would be a trivial fix. Without it you're looking at a very long process of migrating files and setting up anything that isn't migratable. If you're able to even read the original.
     
    Last edited: Apr 4, 2023
  9. DrLulz

    DrLulz

    Joined:
    Nov 14, 2022
    Posts:
    11
    OH MY GOD I AM MADE OF THE BIG DUMB!

    here's what was wrong:
    i accidentally turned on "Error Pause" in the console.

    since i have an error at start when it's searching for a game object that hasn't been initialized yet it would just instantly pause the game.

    that also explains why build and run still worked.
     
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,175
    Oh. I don't think I've ever used that so I never would have thought of it. :p
     
  11. DrLulz

    DrLulz

    Joined:
    Nov 14, 2022
    Posts:
    11
    i didn't even know it existed till right now.