Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Bug Unity crashed and now my project is having problems.

Discussion in 'Editor & General Support' started by PowerJake, May 24, 2022.

  1. PowerJake

    PowerJake

    Joined:
    Nov 15, 2019
    Posts:
    64
    [unity 2021.3.2f1]

    Hey, sorry if this has been brought up before, but I haven't been able to find any posts about it.

    I was working on adding a flagpole for checkpoints in my game when the editor crashed. Since then my flag pole script has not been working. None of its references to itself or serialized fields seem to work. I am having trouble diagnosing what went wrong.

    Here is the entire CheckpointFlag script:
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class CheckpointFlag : MonoBehaviour {
    7.     public CheckPoint checkPoint;
    8.  
    9.     public Animator flagAnimator;
    10.  
    11.     private void Start() {
    12.         GameManager.CheckPointActivated += OnCheckPointChanged;
    13.     }
    14.  
    15.     private void OnCheckPointChanged(string cname) {
    16.         Debug.Log(checkPoint + " " + flagAnimator, gameObject); // line 16
    17.         flagAnimator.SetBool("raised", checkPoint.name.Equals(cname));
    18.     }
    19. }
    Here is a screen shot of the problem in action:
    nullbutnot.PNG

    The exception in the console there is complaining about the CheckpointFlag's own gameObject that I pass as context on line 16 was destroyed, though we can clearly see it is still there in the scene. If I take the context off of line 16 then it will print "null null", which shows that the CheckPoint and FlagAnimator fields are also busted, despite them clearly being set in the inspector.

    This happened right before I hit play on the game again and found my bullet prefabs had all of their references and values reset to 0s and nulls. Could my project be corrupt and these problems are related?

    Another thing that I suspect may be related (only because I don't know what it did) is that I deleting everything in my script assemblies folder as suggested by this thread for another problem. I don't know what effect that could have had on my project. It didn't fix that problem, but it didn't seem to break anything so I kept working.

    Thanks for reading. Any effort to help me diagnose the issue is greatly appreciated!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,889
    I'm sorry you've had this issue. As far as diagnosing and recovering from it, unless you made backups or use source control, you basically have to go through each part and make sure it is all correct again.

    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

    Here's 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.

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

    PowerJake

    Joined:
    Nov 15, 2019
    Posts:
    64

    This is excellent advice. Thankfully I have been using source control and I can go back to before this issue got to messing things up. I just didn't want to lose the work that I had done since the probable cause of this problem came up. But it looks like I should just bite the bullet and get this over with. Thanks for the response. Your git solution looks to be more robust than my workflow so I still have something to learn here, without the heartache of losing my project.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,889
    Go use the source control to see what is different, what got corrupted!!