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 rynwin · Nov 05, 2014 at 03:06 AM · procedural generationload scenesave sceneload level

Go back and forth between procedurally generated levels?

I'm creating a procedurally generated maze with multiple levels. I already have the code for generating the maze; that's not the issue.

The issue is I need the player to be able to backtrack to the entrance of the first level of the maze from any level, so all of the levels need to be saved (as scenes, I assume) but I don't want a fixed number of levels, so making a list of scenes in the build settings doesn't seem like the way to go. It seems like this should be simple but, being a noob, I just can't figure out how.

Maybe I'm just searching with the wrong keywords, but so far I'm only finding tutorials for procedural map generation or going back and forth between preexisting scenes listed in the build settings.

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
1

Answer by robertbu · Nov 05, 2014 at 03:08 AM

Not much information here about your procedural levels. Typically levels like these are generated from random values. Generate and save a seed for the Random class. Using the same seed should generate the same level. You can use PlayerPrefs to save the seed for each level, or if it is only during a single run of the app, you can use DonDestroyOnLoad:

http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

Comment
Add comment · Show 3 · 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 rynwin · Nov 06, 2014 at 06:47 AM 0
Share

I used this tutorial for the basis of the maze http://catlikecoding.com/unity/tutorials/maze/ so I'm not sure how that would work, since a seed wasn't involved.

While DontDestroyOnLoad could probably be a key part of the solution, I would still first need to be able to create new scenes via code, and I can't seem to find information on how to do that.

avatar image robertbu · Nov 06, 2014 at 07:14 AM 1
Share

So just before you generate your maze, add this line of code:

  Random.seed = 1234;

http://docs.unity3d.com/ScriptReference/Random-seed.html

If you set the seed for Unity's Random class to the same value before calling your maze generation code, you should get the same maze every time. Note I personally find it easier when I do things like this to use the .NET Random class for areas I want to manipulate the seed. It works a bit differently, and since it has the same name, it can be a bit tricky to use both, but you get an instance of a class with .NET Random, so you can isolate the manipulation of the seed value.

avatar image rynwin · Nov 06, 2014 at 10:24 AM 0
Share

I guess I could randomly generate the seed for Random.seed the first time the player enters the level and then use that same seed every other time the player enters the level; since I don't want the player to get the same maze every time they start a new game.

It seems a little more complicated than just saving the scene as-is; I will also have collectibles and a few monsters, and I don't want them all resetting when the player backtracks, but I already have a few ideas for how to handle that.

Thanks.

avatar image
0

Answer by Cherno · Nov 05, 2014 at 12:37 PM

"Just" save all the information bout a level in a file (size, block information, objects, player start positions etc.) and when you need to change a level, you first clear the scene and then generate the new level by looking up the informtion from your file. In effect, you have only one Unity scene which gets used for building any level when needed.

Comment
Add comment · Show 3 · 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 rynwin · Nov 06, 2014 at 06:59 AM 0
Share

And is there a tutorial for that somewhere? It's all well and good to say "you need to do this kind of thing" but I already understood that the two most blatantly obvious possibilities were either creating a new scene every time the player goes to the next level without destroying the previous level, or saving the level data and clearing the scene each time, then loading from that data.

What I need to know is "how," and so far I haven't come across a usable resource for either case. If you know of one, please point me to it.

avatar image b1gry4n · Nov 06, 2014 at 07:10 AM 0
Share

You should not rely on tutorials for anything other than getting familiar with the topic you are dealing with. Work on understanding what is happening in the tutorials and then implement it yourself for your custom(hopefully unique) situation

avatar image rynwin · Nov 06, 2014 at 10:05 AM 0
Share

Which still requires a tutorial on the relevant topic, duh. I'm looking for a tutorial on one aspect of a larger project I'm working on; just like I used part of a tutorial for the maze, ignored anything I didn't want, and then added my own features to it. I'm also a total newbie to both program$$anonymous$$g and unity, so naturally I'm going to tend to be more reliant on tutorials.

I'm doing my own project from the get-go ins$$anonymous$$d of just copying a tutorial wholesale, because if I'm not working on something I'm interested in I won't have the drive to keep with it. In other words, I'm doing exactly what you just passive-agressively chastised me for not doing; which should really have been totally obvious given that I was only looking for a tutorial relevant to a specific aspect of the game.

Seriously, if you don't have anything useful to add, why even comment? Does it feed your ego or something?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Game freezes loading a new scene with Android split application (APK + OBB) 1 Answer

How to load player last scene visited 1 Answer

loadscense very slow 0 Answers

Create an autosave/checkpoint feature for my game? 1 Answer

Crash when save scene or load scene. 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