SetActive() not working (giving error)

Hi!

I have made am extremely simple script to activate / deactivate certain Gameobjects depending on the game stage, but it is giving me an error for some reason and i am starting to get mad…

i leave you with the script and an image…

using UnityEngine;

public class switchPhase : MonoBehaviour
{
    public bool buildPhase = false;

    [SerializeField] GameObject bM;
    [SerializeField] GameObject cM;

    void Start()
    {
        SwitchPhases();
    }

    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Return)) SwitchPhases();
    }

    void SwitchPhases()
    {
        if (buildPhase)
        {
            bM.SetActive(false);
            cM.SetActive(true);
            buildPhase = false;
        }
        else
        {
            bM.SetActive(true);
            cM.SetActive(false);
            buildPhase = true;
        }
    }
}

Error:

UnassignedReferenceException: The variable bM of switchPhase has not been assigned.
You probably need to assign the bM variable of the switchPhase script in the inspector.
switchPhase.SwitchPhases () (at Assets/Scripts/switchPhase.cs:30)
switchPhase.Start () (at Assets/Scripts/switchPhase.cs:12)

Thanks for any help!!!

sounds like that code is on something else too

omfg that was it :sweat_smile:
ty so much!!!

1 Like