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
1
Question by exiledscot · Mar 10, 2012 at 01:03 PM · instantiatescenescene-loadinggamestate

Saving and loading level/game state

Hi I'm quite a noob with unity and I'm trying to create a dungeon crawler game in the style of Dungeon Master et al.

My problem is saving the actions the player has performed. I need this as its possible for a player to not only go forward through the levels but also revisit levels they've already passed through.

For example: If the player unlocks and opens a door before proceeding to the next level I want that door to be unlocked and open when the player revists the level.

I know about playerPrefs but would prefer not to use this as the game will be Windows based(and hence clog the registery with tonnes of info).

I'm not looking for ready made scripts but just advice and maybe a few pointers on how I can do this.

Thanks for reading

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
1
Best Answer

Answer by AlucardJay · Mar 10, 2012 at 02:49 PM

have a look at Object.DontDestroyOnLoad .

This is from the Unity Script Reference :

static function DontDestroyOnLoad (target : Object) : void

Description

Makes the object target not be destroyed automatically when loading a new scene.

When loading a new level all objects in the scene are destroyed, then the objects in the new level are loaded. In order to preserve an object during level loading call DontDestroyOnLoad on it. If the object is a component or game object then its entire transform hierarchy will not be destroyed either.

// Make this game object and all its transform children
// survive when loading a new scene.
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}

So maybe you could create an empty game object, and save all your variables to it before you do Application.LoadLevel .

So for example , let's call the object Logger :

public var Health : float = 0.0; public var Gold: int = 0; public var Backpack: Array = ["Stamina Potion, "Gold key"];

function Awake () { DontDestroyOnLoad (transform.gameObject); }

Then on the Player Script :

function UpdateLogger () {
var Logger = GameObject.Find("Logger_Object").GetComponent(Logger_Script);
Logger.Health = myHealth;
Logger.Gold = myGold;
Logger.Backpack = myBackpack;
}

This is just a basic answer as I am a noob myself. Personally I would put the =>

var DontDestroy = GameObject.Find("Logger_Object").GetComponent(Logger_Script);

<= statement in a Start or Awake function, so it only searches once to load the Logger Script. Hope this helps.

Comment
Add comment · Show 13 · 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 exiledscot · Mar 10, 2012 at 03:28 PM 0
Share

Thanks but I am already using a game$$anonymous$$anager script thats persistent. Its the saving/loading of the data that im having problems with as i dont want to use PlayerPrefs.

avatar image exiledscot · Mar 10, 2012 at 03:32 PM 0
Share

Sorry I read youre answer wrongly the 1st time.I am already using a game$$anonymous$$anager script thats persistent. Its the saving/loading of the data that im having problems with as i dont want to use PlayerPrefs.

avatar image exiledscot · Mar 10, 2012 at 04:53 PM 1
Share

DOH!

Thanks alucardj I was looking at it from the game$$anonymous$$anager Object. Loading all the states then calling all the classes methods to update them. I didnt think of doing it that way. I told you I was making it more difficult than it should ber :D

Thanks again man.

avatar image Kleptomaniac · Apr 11, 2012 at 05:43 AM 1
Share

Haha, @alucardj the accept rate is pointless ... accepts are just so people who go looking here can easily find which solution worked best. $$anonymous$$arma is where it's at man!

avatar image fafase · Apr 11, 2012 at 06:15 AM 1
Share

Well, neither of both pays the bill though.

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I reset part of a scene? 1 Answer

SceneManager.GetAllScenes() only returns the current scene 3 Answers

,Enums not being passed between scripts properly 1 Answer

Loading a scene 1 Answer

How to get the position of a new Instantiated prefab 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