NoobProgrammer
NoobProgrammer

Reputation: 488

Destroyed GameObject but still trying to access it

EntryPoint.cs

protected IEnumerator LoadAsync(string prf_path, Transform prt_tf, bool is_enable = true)
{

    ResourceRequest res_req = Resources.LoadAsync<GameObject>(string.Format(prf_path, quality));
    res_req.priority = 0; // = ThreadPriority.Low;
    yield return res_req;

    if (res_req == null || res_req.asset == null)
    {
        res_req = Resources.LoadAsync<GameObject>(string.Format(prf_path, "HIGH"));
        res_req.priority = 0; // = ThreadPriority.Low;
        yield return res_req;
        Debug.LogFormat(prf_path, "HIGH");
    }
    else
    {
        Debug.LogFormat(prf_path, quality);
    }

    GameObject prf = res_req.asset as GameObject;
    GameObject obj = Instantiate(prf);

    obj.transform.SetParent(prt_tf);
    obj.transform.localScale = Vector3.one;
    obj.transform.localRotation = prf.transform.localRotation;
    obj.transform.localPosition = prf.transform.localPosition;
    obj.name = prf.name;
    yield return new WaitForEndOfFrame();
    obj.SetActive(is_enable);
}

LOBBYUI: I have an option which is Option Rendering and Option Livestreaming. Now here's the problem . When i tried to run my program for the very first time and choose Option Livestreaming it will work then i'll logout then it will go back to my LobbyUI and choose the Option Rendering. Then this error will come out

Object of type 'GameObject' has been destroyed but you are still trying to access it.

Now when i tried this line of code

if (obj != null)
    {
        obj.SetActive(is_enable);
    }

It will point out to my object which is initiated and that's pretty weird . Any idea?

EDIT:MORE INFO

I load my resources using this line of code:

MC_EntryPoint: EntryPointA

 if (PlayerPrefs.GetInt(OptionPopup.LiveStreaming_) == 1)
    {
        tf = transform.Find("UI Root/FullscreenPanel/Screen3DUI/panel (depth 1~2)");
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/logo", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/card_open_window", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/ranking", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/streaming_feed", tf));

        tf = transform.Find("UI Root/FullscreenPanel/Screen3DUI/panel (depth 10~11)");
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/midterm_loading", tf));

        tf = transform.Find("UI Root/FullscreenPanel/Screen3DUI/panel (depth 12)");
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/game_result", tf));
    }
    else
    {
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/minimap_type_b (x_ 1575, 1356)", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/replay", tf));

        tf = transform.Find("UI Root/FullscreenPanel/Screen3DUI/panel (depth 1~2)");
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/logo", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/card_open_window", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/ranking", tf));
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/top_bar", tf));

        tf = transform.Find("UI Root/FullscreenPanel/Screen3DUI/panel (depth 10~11)");
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/midterm_loading", tf));

        tf = transform.Find("UI Root/FullscreenPanel/Screen3DUI/panel (depth 12)");
        yield return StartCoroutine(LoadAsync("MC_VERSION/{0}/UI/Screen3DUI/game_result", tf));
    }

    loading.SetValue(0.02f);    // 2%.

So it's something like . Is there any other way load some of my UserInterface if i'm from Livestreaming(which i do not load some UI) to Rendering (which i load some UI).

EntryPointA:EntryPoint

protected override IEnumerator Init()
{
    tzPlayInfo.Instance.BLOCK_GAME_FLOW = true;
    tzPlayInfo.Instance.MAKING_GAME_OBJECT = true;
    //start_time = Time.realtimeSinceStartup;
    loading.SetValue(0f);       // 0%.

    yield return StartCoroutine(InitSystem());
    //Debug.Log(string.Format("End InitSystem - {0}s", Time.realtimeSinceStartup - start_time));
    loading.SetValue(0.01f);    // 1%.

    yield return StartCoroutine(InitUI());
    //Debug.Log(string.Format("End InitUI - {0}s", Time.realtimeSinceStartup - start_time));
    loading.SetValue(0.05f);    // 5%.

    yield return StartCoroutine(InitGO());
    //Debug.Log(string.Format("End InitGO - {0}s", Time.realtimeSinceStartup - start_time));
    loading.SetValue(0.95f);    // 95%.

    yield return StartCoroutine(InitServerDependentInfo());
    //Debug.Log(string.Format("End InitServerDependentInfo - {0}s", Time.realtimeSinceStartup - start_time));
    loading.SetValue(0.96f);    // 96%.

    yield return StartCoroutine(Recheck());
    //Debug.Log(string.Format("End Recheck - {0}s", Time.realtimeSinceStartup - start_time));
    loading.SetValue(1f);       // 100%.
    CameraManager.Instance.TurnOnCamera(eCmr.PADDOCK_1); // 로딩이 끝나면 카메라를 켠다.
    tzPlayInfo.Instance.BLOCK_GAME_FLOW = false;

    Destroy(loading.gameObject);    // 첫로딩 UI 삭제.
    Destroy(this);                  // EntryPoint 컴포넌트 삭제.
}

EDITTED QUESTION

I guess the information I provided was a bit stiff so i edited it. And i'm guessing that it is null because I destroy something??? Please enlighten me.

Upvotes: 1

Views: 352

Answers (2)

NoobProgrammer
NoobProgrammer

Reputation: 488

I'll answer my own question . What i did here is that this line of code

protected IEnumerator LoadAsync(string prf_path, Transform prt_tf, bool is_enable = true)
{

    ResourceRequest res_req = Resources.LoadAsync<GameObject>(string.Format(prf_path, quality));
    res_req.priority = 0; // = ThreadPriority.Low;
    yield return res_req;

    if (res_req == null || res_req.asset == null)
    {
        res_req = Resources.LoadAsync<GameObject>(string.Format(prf_path, "HIGH"));
        res_req.priority = 0; // = ThreadPriority.Low;
        yield return res_req;
        Debug.LogFormat(prf_path, "HIGH");
    }
    else
    {
        Debug.LogFormat(prf_path, quality);
    }

    GameObject prf = res_req.asset as GameObject;
    GameObject obj = Instantiate(prf);

    obj.transform.SetParent(prt_tf);
    obj.transform.localScale = Vector3.one;
    obj.transform.localRotation = prf.transform.localRotation;
    obj.transform.localPosition = prf.transform.localPosition;
    obj.name = prf.name;
    yield return new WaitForEndOfFrame();
    obj.SetActive(is_enable);
}

Doesn't work on Android Phone . It's basically for PC Platform only . So right now currently I'm making a method for Mobile. I'll edit my answer after i finish this up. Thanks guys

Upvotes: 0

MGDroid
MGDroid

Reputation: 1659

Unable to comment but did you check that you are not trying to access that gameObject from other place? may be any reference ? Or you are using singleton?

Upvotes: 1

Related Questions