I made a script that spawns (instantiates) random game objects at random positions in a scene, on a Start()
. But I have two problems:
If I change scene and I come back, the instantiated objects are not there anymore, i.e., they are not permanent. How do I make them permanent like those objects I placed in the scene through the Unity editor? I'm not talking about
dontdestroyonload
, which keeps the objects across all scenes and never destroys them.My spawn script, which I want to run only once when the scene is loaded for the first time, runs every time I come into the scene instead, even if I added a line in the script that destroys both the script and the parent game object. I want it to run once and be gone forever. How does one do that?