Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 zeman97 · May 02, 2013 at 04:14 AM · objectsceneobjectsrespawnwithout

How to change scenes without reloading them.

Hey guys! I am making an open-world game and I am running into a small issue. My player and all things associated with him are static and DontDestroyOnLoad, that's not the issue. My issue is that objects (such as weapons) are respawning when I exit the building scene and into the exterior scene. How do I prevent this?

Any help would be greatly appreciated! Thanks!

Here is the general code I am using:

 void Update()
 {
    if(Input.GetKeyUp(KeyCode.E))
    {
       Application.LoadLevel(1);
    }
 }
Comment
Add comment · Show 1
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 Karsnen_2 · May 02, 2013 at 04:28 AM 0
Share

I am quite interested to know about this.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Loius · May 02, 2013 at 05:25 AM

Save the state of the scene and on scene load destroy objects that should be gone based on that save.

PlayerPrefs is probably the hassle-free-est way to save scene state. At the very simplest each object would store its name in PlayerPrefs if it wants to suicide next time the level loads.

There's some serializer by whydoidoit that does stuff you might want: http://whydoidoit.com/unityserializer/

Comment
Add comment · 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
1

Answer by Fornoreason1000 · May 02, 2013 at 05:32 AM

you could make a "temp" class that handles any recent events such as the weapon you picked up, the enemies you killed. if the player has picked up those weapon or killed those enemies, you can make a temp file saying so, so when you exit and re-enter the dead bodies disappear and the weapons don't re spawn. you can clear this temp or cache after a certain amount of levels to prevent it from building to massive size but only keep the last 3 or so level you were in. the thing about this method, if you shutdown the game , whether you save or not, the temp will be recreated, so all the weapons and enemies re spawn. this is actually a good thing in some cases to stop players from getting bored.

you might want to make the Temp class static... you don't want to create new instances of temp on each object, it really depends on your scripting heirachy. when you load a level Temp should check for the state of the scene you left it in, and set the states for the objects, e.g Enemy A killed at 2,0,0 and it was kill them and place them there. weapons it will destroy ones you already picked up. etc.

another option is to save the data via PlayerPrefs, but I wouldn't advise this for open world games since the large save file you may end up with. but you may do so, for once only pick ups or scripted enemies.

Comment
Add comment · 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

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

15 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

Related Questions

Problem with draging object to scene 2 Answers

What are GameTiles? 1 Answer

Change Object's Origin 1 Answer

Select object in another scene 1 Answer

Persistent game objects 1 Answer


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