Scripts suddenly not working

This morning I discovered that almost all of my scripts in a small project I have been working on have stopped working. They were working yesterday just fine and I didn’t change anything in Unity between when they were working and this morning when I discovered the scripts to no longer be working. What could have possibly caused this?

1 Like

What is not working?
Post your script.
Remember to use Code Tag.

1 Like

“Not working” could mean anything. Do you have an error message?

1 Like

Gonna need more information.

Do you have any compile errors in the console?
Look at the objects in the scene. Do you still see your scripts in the inspector?
Are the script files themselves still present?

1 Like

I get no errors in my console of any kind. All of the scripts are still attached and any object a script was referencing is still showing in the inspector. Here’s one of my scripts:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fire : MonoBehaviour
{
    public ParticleSystem flames;

    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Collision!");
        flames = collision.gameObject.GetComponent<ParticleSystem>();
        flames.Play(true);
       
    }
}

Just yesterday the particle system would play when the collision occurred but now nothing happens. Here’s another script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Explode : MonoBehaviour
{

    private int counter = 0;
    public GameObject explosion;
    public Rigidbody ball;

    private void OnCollisionStay(Collision collision)
    {
        Debug.Log(collision.gameObject.name + " rolled onto " + gameObject.name + " counter + " + counter);

        counter += 1;

        if (counter == 30)
        {
            Destroy(gameObject, .4f);
            Instantiate(explosion);
            explosion.SetActive(true);
            ball.AddForce(Vector3.up * 500f);

        }

    }

I opened a new scene and was only able to get this script to work after removing and reattaching the explosion object and Rigidbody. Is it possible that my original scene was corrupted? One day it was working fine, the next my scripts no longer worked as they had. No errors of any kind to indicate what could be wrong.

Chances are, you haven’t saved scene.

That doesn’t seem to be the problem. Even after saving the scene it still doesn’t work. This script was executing as expected yesterday, today nothing happens. No errors, no Deb.Log message in the console, nothing.

If you make a brand new script that does something trivial and detectable (e.g. Debug.Log in Start), and put that in your scene, does that work?

I am having the same problem. One of my scripts wasn’t working so I closed Unity and when I came back none of them were working anymore, even though they were unaltered.

I have been having the same problem same code in test scenes works fine in my main scene does not work with any errors code has not changed works fine in the test scene the same prefab in the main scene nothing tested back to back creat a new scene drop in prefab works close unity and start it again stops working. Project corrupt because it keeps happening what recreate everything what can I port and not port to new build.

yeah its any scene I close on as well it happens

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]

public class Door : MonoBehaviour
{
    [SerializeField] GameObject[] switches = new GameObject[] { null };
    private string[] reqSwitches;

    private int index;
    public string key;
   
    Vector3 startPos;
    Vector3 lerpPos;

    // Start is called before the first frame update

    private bool CheckSwitches()
    {
        bool output = false;

        for(int i = 0; i < switches.Length; i++)
        {
            GameObject curGO = switches[i];
            string key = curGO.GetComponent<Switch_Pressure>().key;
            int index = SwitchData.FindKeyIndex(key);

            int lastSwitchIndex = Mathf.Clamp(i, 0, switches.Length - 1);
            GameObject lastGO = switches[lastSwitchIndex];
            string lastKey = lastGO.GetComponent<Switch_Pressure>().key;
            int lastIndex = SwitchData.FindKeyIndex(key);

            if(!SwitchData.switches[lastIndex].onOff && SwitchData.switches[this.index].onOff)
            {
                output = false;
                SwitchData.switches[lastIndex].onOff = false;
                SwitchData.switches[this.index].onOff = false;
                break;
            }
            else
            {
                output = SwitchData.switches[this.index].onOff;
            }
        }

        return output;
    }

    private void Start()
    {
        startPos = transform.position;
        lerpPos = new Vector3(transform.position.x, transform.position.y + 12, transform.position.z);
    }

    private void SetDoorsState(bool openClose)
    {
        if(openClose)
        {
            Debug.Log("Door Open");
            transform.position = Vector3.Lerp(transform.position, lerpPos, Time.deltaTime * 2);
        }
        else
        {
            transform.position = Vector3.Lerp(transform.position, startPos, Time.deltaTime * 2);
        }
    }

    [SerializeField] bool openClose = false;

    // Update is called once per frame
    void FixedUpdate()
    {
        Debug.Log("Door Open " + name);

        if (switches[0] != null)
        {
            SetDoorsState(openClose);
        }
    }
}
/*everything else its connected to works switches change material color to green and the database updates can see the switches data in the save file and everything the save file even logs the door opening.*/

Someone can help would be great feeling like maybe I am making a mistake because results are inconsistent I am trying to build a switch network so if they are not hit in right order and if other switches are hit that others will turn off.

You’re posting random comments and random code to a thread that is over two years old.

Please instead choose to set yourself up for success on the forums and START YOUR OWN FRESH POST, it’s FREE.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220