Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CiphersoftStudios · Dec 04, 2021 at 11:50 PM · instantiatedestroyspawnreferencespawning

Losing references after reloading the scene, even though they exist again.

So basically im creating a space sandbox game on mobile where you can create your own universe. At the start of the game you can choose your rocket. Every rocket has its own Camera, Player and Spawner attached to it. Not the nicest solution but it works. After the player chooses his rocket, I destroy the spawners on the inactives ones, so they dont work. My problem is when exiting the scene and choosing a different rocket and repeating the process, the SpawningManager with all the references to all Spawners lost the references to them. Even though I reloaded the scene all references are still lost. Sorry if this was hard to follow but it was hard to explain.

Here is a part of the code that destroys the spawners(represented by colors)

 if (BlueSelected == true)
         {
             Destroy(RedSpawner);
             Destroy(OrangeSpawner);
             Destroy(YellowSpawner);
             Destroy(GreenSpawner);
         }

And a part of one of the planet spawner(represented by colors)

 {
     public Transform SpawnPointBlue, SpawnPointRed, SpawnPointOrange, SpawnPointYellow;
     public GameObject Mercury;
 
     // Checks if the Spawner is greater than null (There or not) and Instantiates the Object at the Players Position
     public void SpawnMercury()
     {
         
         if(SpawnPointBlue != null)
         {
             Instantiate(Mercury, SpawnPointBlue.position, SpawnPointBlue.rotation);
         }
 
         if(SpawnPointRed != null)
         {   
             Instantiate(Mercury, SpawnPointRed.position, SpawnPointRed.rotation);
         }
 
         if(SpawnPointOrange != null)
         {   
             Instantiate(Mercury, SpawnPointOrange.position, SpawnPointOrange.rotation);
         }
 
         if(SpawnPointYellow != null)
         {   
             Instantiate(Mercury, SpawnPointYellow.position, SpawnPointYellow.rotation);
         }




Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by KittenSnipes · Dec 05, 2021 at 12:48 AM

So why destroy these spawn points in the first place? I recommend just setting them inactive and when needed set them active again.

All you need to do is get the gameobject of these spawners and then use the function to turn them off here is an example:

 //This sets the object inactive
 GreenSpawner.gameObject.SetActive(false);
 //This sets the object active
 GreenSpawner.gameObject.SetActive(true);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CiphersoftStudios · Dec 05, 2021 at 08:57 AM 0
Share

Oh yeah, thanks a lot for your reply! Looking back im not sure why I wanted to destroy them either. This solution kinda just went over my head. I just read the unity documentation about SetActie so hopefully I wont run into there problems again. Thanks a lot for the help =)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

161 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to destroy a object only in game and not the prefab 2 Answers

Prevent object from spawning at a spawn point twice in a row? 3 Answers

How to Spawn after checking if the clones are destroyed. 1 Answer

Have a spawning issue on iOS 0 Answers

instanstiate Spawns more then one objec 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges