0
\$\begingroup\$

In one script i did:

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

public class GameManager : MonoBehaviour
{
    public LevelGenerator levelGenerator;

    // Use this for initialization
    void Start ()
    {

    }

    // Update is called once per frame
    void Update ()
    {

    }

    private void OnApplicationQuit()
    {
        levelGenerator.DestroyNodes();
    }
}

Then in the other script:

public void DestroyNodes()
    {
        GameObject[] nodes = UnityEngine.GameObject.FindGameObjectsWithTag("Node");

        if (nodes.Length == 0)
        {
            //Debug.Log("No nodes to destroy found");
        }
        else
        {
            for (int i = 0; i < nodes.Length; i++)
            {
                DestroyImmediate(nodes[i]);
            }
        }
    }

But the Nodes still exist in the Hierarchy and in the Game and Scene views.

I used a breakpoint it's getting to the OnApplicationQuit

And it's getting to the line:

DestroyImmediate(nodes[i]);

There are 100 objects and it's doing the line for each object. But then when i make continue they are still exist.

I want that when i quit the game stop the play all the gameobjects to be destroyed.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If the nodes were there before you hit play, they will reappear when you hit stop even if you delete them. The scene state is restored after stop playing

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .