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. Dismiss Notice

Question Script component becomes inactive

Discussion in 'Editor & General Support' started by donbonbon, Aug 31, 2023.

  1. donbonbon

    donbonbon

    Joined:
    May 28, 2023
    Posts:
    20
    I cannot activate the scripts attached to an empty gameobject.
    I wanted to check a simple Canvases flow in my maingamemanager.cs. I thus commented out the cardmanagar and playermanager snippets from the script.
    Doing so, the activate box of the scripts components for cardmanager and playermanger disappeared.

    After testing, I uncommented the related references but the script components remain hidden. I closed and open unity hub, I deleted the library to remove all cache, I reimported all. The activate boxes are still missing.

    If I create a new project, I can overcome this issue. Yet, this isn't the first time it happens to me. It would be nice the know how to handle it, besides activating the nuclear option.

    Any advice would be highly appreciated.

    PS - in case it's relevant, here's the script.

    The cardmanager and playermanager were executed as expected. All references are properly assigned.

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class MainGameManager : MonoBehaviour
    5. {
    6.     public Canvas setupCanvas;
    7.     public Canvas gameUICanvas;
    8.     public Canvas endgameCanvas;
    9.     //I commented and uncommented these references
    10.     public PlayerManager playerManager; // Reference to the PlayerManager script
    11.     public CardManager cardManager; // Reference to the CardManager script
    12.  
    13.     private bool isPlayersGenerated = false;
    14.     private bool isCardsGenerated = false;
    15.  
    16.     private void Start()
    17.     {
    18.         StartCoroutine(GameFlow());
    19.     }
    20.  
    21.     private IEnumerator GameFlow()
    22.     {
    23.         Debug.Log("GameFlow started");
    24.         // Start PlayerManager and CardManager through their wrapper methods
    25.         playerManager.StartGeneratePlayers();
    26.         cardManager.StartGenerateCards();
    27.  
    28.         // Wait until both managers have completed their tasks
    29.         yield return new WaitUntil(() => isPlayersGenerated && isCardsGenerated);
    30.         Debug.Log("Players and Cards generated");
    31.  
    32.         // Distribute cards to players after cards are generated
    33.         //cardManager.DistributeCards();
    34.  
    35.         // Show canvases
    36.         yield return StartCoroutine(ShowCanvasForDuration(setupCanvas, 4f));
    37.         yield return StartCoroutine(ShowCanvasForDuration(gameUICanvas, 4f));
    38.         yield return StartCoroutine(ShowCanvasForDuration(endgameCanvas, 4f));
    39.  
    40.         // Automatically transition to the next scene or perform other actions here.
    41.     }
    42.  
    43.     // Set this method to be called by the PlayerManager when players are generated
    44.     public void OnPlayersGenerated()
    45.     {
    46.         Debug.Log("Players generated!");
    47.         isPlayersGenerated = true;
    48.     }
    49.  
    50.     // Set this method to be called by the CardManager when cards are generated
    51.     public void OnCardsGenerated()
    52.     {
    53.         Debug.Log("Cards generated!");
    54.         isCardsGenerated = true;
    55.     }
    56.  
    57.     private IEnumerator ShowCanvasForDuration(Canvas canvas, float duration)
    58.     {
    59.         // Deactivate other canvases
    60.         setupCanvas.gameObject.SetActive(false);
    61.         gameUICanvas.gameObject.SetActive(false);
    62.         endgameCanvas.gameObject.SetActive(false);
    63.  
    64.         // Activate the current canvas
    65.         canvas.gameObject.SetActive(true);
    66.  
    67.         // Wait for the specified duration
    68.         yield return new WaitForSeconds(duration);
    69.  
    70.         // Deactivate the current canvas
    71.         canvas.gameObject.SetActive(false);
    72.     }
    73. }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    What does this actually mean?

    If you mean the checkbox that sometimes appears in the component's header, that only appears when certain Unity messages are implemented as outlined in the documentation: https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
     
  3. donbonbon

    donbonbon

    Joined:
    May 28, 2023
    Posts:
    20
    That was what I meant. and in addition your tip solved my problem. A good English tip and less of a headache before lunchtime is highly appreciated. Thanks!!
     
    Last edited: Aug 31, 2023
  4. donbonbon

    donbonbon

    Joined:
    May 28, 2023
    Posts:
    20
    That was what I meant and it also solved my problem. So thanks for the English tip and solving my problem. Highly appreciated.