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
4
Question by chaosTechnician · Jul 29, 2010 at 11:03 PM · scene-loading

How can I determine if a Scene exists in a Project?

I'm working on what is intended to be an arcade-style, simple, streaming web game. When the last level is reached, I want to be able to reload the first (with a difficulty modifier, of course) and continue play. Each level is its own scene and I'm having no problems loading the next level until I reach the last one.

I'm unable to find any way to programmatically determine when I'm out of scenes. Since I can't tell when I run out, I can't tell when I need to go back to the first one. The current code I have to load the next level is:

if(Application.CanStreamedLevelBeLoaded(LevelNumber.ToString()))
   Application.LoadLevel(LevelNumber.ToString());

Where LevelNumber is an int representing the level number to load next. Is there a way to check is a Scene with a given name exists within the Project so I can set LevelNumber back to 1 when I have no more available levels?

I am aware that I could set another variable representing the maximum number of levels there are but I'd prefer to have the program itself handle it so I can include or exclude levels for various builds (for testing and otherwise) without having to remember to change a game constant.

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

Answer by Mike 3 · Jul 29, 2010 at 11:27 PM

Application.levelCount will give you how many levels there are. Then you just need to check if the current level is < levelCount

Also - why're you using the string version of the LoadLevel instead of the int one?

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 chaosTechnician · Jul 30, 2010 at 12:36 AM 0
Share

Nice, I must have missed levelCount. It seems like it may be my best bet--which will make my reasoning for the use of LoadLevel(string) obsolete. It was a hastily made decision to make things a bit more simplified when I have a friend of $$anonymous$$e help with level design once the engine is at about beta.

avatar image
10

Answer by ffff1111 · Jan 26, 2013 at 01:48 AM

Curiously, this works also with standalone scenes:

Application.CanStreamedLevelBeLoaded

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 yoyo · Feb 03, 2015 at 09:19 PM 2
Share

Excellent, thanks for this. (Now, it would really be nice if there was a method Application.GetLevelName(int index) ...)

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

2 People are following this question.

avatar image avatar image

Related Questions

DontDestroyOnLoad, where is my error? 2 Answers

UI button loading wrong scene 1 Answer

Loaded two scenes asynchronously, neither will activate? 1 Answer

How do I determine the reason why an asset has been unloaded? 1 Answer

Problem loading a scene and initializing it before it is displayed 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