Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 jameshutson108 · Nov 17, 2019 at 01:18 PM · platformerrespawnsave scene

Save game progress at respawn points

Hi, I am new to unity and hoping someone can help. I have a 2d Platformer game. It is one large level, but as the player progresses through the level there are respawn points. when the player passes them, it saves the players position so when he dies he returns to this point. I have this working perfectly.

However, I also need the game to save the progress at this point - i.e. all enemies killed, all coins collected, all buttons pushed etc. If the player dies before he gets to the next respawn point: - He returns to the last respawn point he passed, - Everything he did after passing that respawn point is reset and has to be done again - Everything he did before passing that respawn point stays exactly as he left it (i.e. all coins collected etc).

There are literally hundreds of coins and objects. What would be the best way to get unity to remember the progress to that point?

Thanks, James

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RadonRaph · Nov 17, 2019 at 02:21 PM

Hello @jameshutson108, There is few ways to save something in Unity, The easiest is to using player prefs !

https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

This work fine and its easy to use. You save something with << PlayerPrefs.SetInt("MyObjectName",0); >> and get it with << int activeness = PlayerPrefs.GetInt("MyObjectName"); >>

So with a little script you can save the state of every object in your games:

 void OnEnable(){
      PlayerPrefs.SetInt(gameObject.name, 1);
 }
 
 void OnDisable(){
      PlayerPrefs.SetInt(gameObject.name, 0);
 }
 
 void Start(){
       if (PlayerPrefs.GetInt(gameObject.name) == 0)
             gameObject.setActive(false);
 }

Hope that will help you,

Raph

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
0

Answer by jameshutson108 · Nov 20, 2019 at 06:24 PM

Thank you @RadonRaph ! I really appreciate the response. I am trying to make this work but the PlayerPrefs do not quite work. For a start, I have multiple game objects in the game, but because they are children of other objects they all have the original prefab name so I cannot use the gameObject.name as an identifier. The other issue is that I need to remember only a number of objects to reset, that is the objects childed to an empty gameobject, and the spawnpoint is also childed. e.g. If a character dies he is returned back to the last spawnpoint, and all gameObjects after that spawn point need to be reset. Is there any way to do this? Thank you, James

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

121 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

Related Questions

I'm trying to make a "Game Over" sound when the player dies and respawns 1 Answer

Getting an object to re-spawn/ transform player back to the beginning 1 Answer

2D 360 degress platformer example needed 0 Answers

Enemies respawn in platform game 1 Answer

2D Platformer - How do I have objects that kill the player upon touch/cause respawn? 2 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