Search Unity

Cannot see why warning: go.IsActive() appears in console

Discussion in 'Scripting' started by Nigey, Jul 2, 2015.

  1. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,115
    Hi Guys,

    I have a class that collects and passes data between objects when they're SetActive(true/false). I have enough control statements within the OnEnable and OnDisable, to make sure the objects are instantiated, and not in the destroy phase, plus double checking that the objects exist before calling functions, however the go.IsActive() warning still appears in the console. No idea what this warning is about or why it's calling, as the game overall is working okay. Here's my code for reference:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameraCoords : MonoBehaviour {
    5.  
    6.     private bool bActiveStatus = false;
    7.  
    8.     void Start()
    9.     {
    10.         bActiveStatus = true;
    11.  
    12.         if (gameObject.name == "BinocularViewCamera")
    13.         {
    14.             if (bActiveStatus)
    15.             {
    16.                 GameObject bwObj;
    17.  
    18.                 if (bwObj = GameObject.Find("_GameWorldData"))
    19.                 {
    20.                     gameObject.transform.position = bwObj.GetComponent<GameWorldData>().GetCameraPosition();
    21.                 }
    22.                 else
    23.                 {
    24.                     Debug.Log("CameraCoords::OnDisable - Cannot yet send data to GameWorldData::mainCameraRot. GameWorldData, not yet instanciated!");
    25.                 }
    26.             }
    27.         }
    28.     }
    29.  
    30.     void OnDestroy()
    31.     {
    32.         bActiveStatus = false;
    33.     }
    34.  
    35.     void OnDisable()
    36.     {
    37.         // Outside of instantiate/clean up phase
    38.         if(bActiveStatus)
    39.         {
    40.             GameObject bwObj;
    41.  
    42.             // Make sure object exists
    43.             if (bwObj = GameObject.Find("_GameWorldData"))
    44.             {
    45.                 // Pass camera's rotation for other camera's to collect
    46.                 bwObj.GetComponent<GameWorldData>().SetCameraRotation(gameObject.transform.rotation.eulerAngles);
    47.             }
    48.             else
    49.             {
    50.                 Debug.Log("CameraCoords::OnDisable - Cannot send rotation to GameWorldData::mainCameraRot! GameWorldData, does not exist!");
    51.             }
    52.         }
    53.     }
    54.  
    55.     void OnEnable()
    56.     {
    57.         // Outside of instantiate/clean up phase
    58.         if (bActiveStatus)
    59.         {
    60.             GameObject bwObj;
    61.  
    62.             // Make sure object exists
    63.             if (bwObj = GameObject.Find("_GameWorldData"))
    64.             {
    65.                 // Collect previously existing camera's rotation
    66.                 gameObject.transform.rotation = Quaternion.Euler(bwObj.GetComponent<GameWorldData>().GetCameraRotation());
    67.             }
    68.             else
    69.             {
    70.                 Debug.Log("CameraCoords::OnEnable - Cannot yet collect data from GameWorldData::mainCameraRot. GameWorldData, not yet instanciated!");
    71.             }
    72.         }
    73.     }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    can we see the full text of the warning... are you sure it's pointing to this script, you aren't using "IsActive()" anywhere in it
     
  3. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,115
    Aaah yes. Here's where the SetActive() is being called. It's from another script referencing these objects.

    Code (CSharp):
    1.     void SetActiveCamera(string camName, string scndName = "")
    2.     {
    3.         GameObject tempObjOne = null;
    4.         GameObject tempObjTwo = null;
    5.  
    6.         foreach (GameObject obj in cameraArray)
    7.         {
    8.             if (camName == obj.name)
    9.             {
    10.                 tempObjOne = obj;
    11.             }
    12.             else if(scndName == obj.name)
    13.             {
    14.                 tempObjTwo = obj;
    15.             }
    16.             else
    17.             {
    18.                 obj.SetActive(false);
    19.             }
    20.         }
    21.  
    22.         // Adding new objects after others have been deleted. Any OnDisable data required, has been already sent to GameWorldObject to be retreived
    23.         // by the objects being enabled, collecting data OnEnable()
    24.         if (tempObjOne)
    25.         {
    26.             tempObjOne.SetActive(true);
    27.             tempObjOne.GetComponent<Camera>().rect = new Rect(0, 0, 1, 1);
    28.         }
    29.         else
    30.         {
    31.             Debug.Log("GameWorldData::SetActiveCamera - tempObjOne is null!");
    32.         }
    33.         if(tempObjTwo)
    34.         {
    35.             tempObjTwo.SetActive(true);
    36.             tempObjTwo.GetComponent<Camera>().rect = new Rect(0, 0, 1, 1);
    37.         }
    38.     }
    39.  
    40.     void CameraShareScreen(string camName, string scndName)
    41.     {
    42.         Rect camTwoRect = new Rect();
    43.         Rect camOneRect = new Rect();
    44.  
    45.         camOneRect.size = new Vector2(0.5f, 1);
    46.         camOneRect.position = new Vector2(0, 0);
    47.  
    48.         camTwoRect.size = new Vector2(0.5f, 1);
    49.         camTwoRect.position = new Vector2(0.5f, 0);
    50.  
    51.         GameObject tempObjOne = null;
    52.         GameObject tempObjTwo = null;
    53.  
    54.         foreach (GameObject obj in cameraArray)
    55.         {
    56.             if (camName == obj.name)
    57.             {
    58.                 tempObjOne = obj;
    59.             }
    60.             else if (scndName == obj.name)
    61.             {
    62.                 tempObjTwo = obj;
    63.             }
    64.             else
    65.             {
    66.                 obj.SetActive(false);
    67.             }
    68.         }
    69.  
    70.         // Adding new objects after others have been deleted. Any OnDisable data required, has been already sent to GameWorldObject to be retreived
    71.         // by the objects being enabled, collecting data OnEnable()
    72.         if (tempObjOne)
    73.         {
    74.             tempObjOne.SetActive(true);
    75.             tempObjOne.GetComponent<Camera>().rect = camOneRect;
    76.         }
    77.         else
    78.         {
    79.             Debug.Log("GameWorldData::CameraShareScreen - tempObjOne is null!");
    80.         }
    81.         if (tempObjTwo)
    82.         {
    83.             tempObjTwo.SetActive(true);
    84.             tempObjTwo.GetComponent<Camera>().rect = camTwoRect;
    85.         }
    86.         else
    87.         {
    88.             Debug.Log("GameWorldData::CameraShareScreen - tempObjTwo is null!");
    89.         }
    90.     }
    The console error is this:

    go.IsActive()
    UnityEngine.GameObject:Find(String)
    CameraCoords:OnDisable() (at Assets/Scripts/CameraCoords.cs:43)
    UnityEngine.GameObject:SetActive(Boolean)
    GameWorldData:CameraShareScreen(String, String) (at Assets/Scripts/GameWorldData.cs:150)
    GameWorldData:SetActiveView() (at Assets/Scripts/GameWorldData.cs:62)
    UnityEngine.EventSystems.EventSystem:Update()
     
  4. lijianwei82475

    lijianwei82475

    Joined:
    Nov 2, 2015
    Posts:
    1
    do not use GameObject.Find() in OnDisable, you can store the reference of your objects at first(for example OnEnable), then you can do what you want to your objects which you attemp to find with GameObject.Find() in OnDisable
     
  5. Hoorza

    Hoorza

    Joined:
    May 8, 2016
    Posts:
    20
    Had a same problem, as lijianwei82475 stated: do not put GameObject.Find() in OnDisable.

    thanks man.