Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Grady · Jul 05, 2011 at 07:59 AM · scenevariableloadtype

Setting variable as type "Scene"

Hey guys,

I want to make the type of my variable a scene, I have tried the following:

 var sceneToLoad : Scene;

and

 var SceneToLoad : scene;

but neither seems to work, can someone tell me what I have to type in for the variable type to make it so that you can enter a scene into the variable????

Thanks

-Grady

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

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Mattivc · Jul 05, 2011 at 08:10 AM

There is no "Scene" object within Unity. The only way to work with scenes is to use: Application.loadedLevel and Application.loadedLevelName together with Application.LoadLevel.

For example

 var sceneName : string = "MainMenu";
 var sceneIndex : int = 0;
 Application.LoadLevel(sceneName); // Load level by name
 Application.LoadLevel(sceneIndex); // Load level by index number


Comment
Add comment · Show 2 · 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 Grady · Jul 05, 2011 at 09:05 AM 0
Share

i thought that might be how i would have to do it....

thanks anyway!!!!

avatar image hich4m · Jul 03, 2012 at 01:18 PM 0
Share

thanks $$anonymous$$attivc , i had to make that clear in my $$anonymous$$d :)

avatar image
7

Answer by Paul-Sinnett · Jul 30, 2014 at 08:42 AM

I wanted to do this because then doesn't matter if you decide to change the scene names in Unity. It turns out you can do it by using the base Object type:

 public Object nextScene;

and then use the "name" member variable:

 Application.LoadLevel(nextScene.name);
Comment
Add comment · Show 2 · 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 Paul-Sinnett · Jul 30, 2014 at 03:31 PM 0
Share

having said that, the scene objects don't seem to get packaged up with the rest of the data so I don't think I can use it

avatar image Ash-Blue · Jun 29, 2016 at 06:16 AM 1
Share

Be warned, storing an Object with a scene will cause it to be stripped during your build creation. Seems Unity manually strips these references and replaces them with null.

avatar image
5

Answer by Syndog · Jul 18, 2016 at 12:30 PM

This is a fairly dated question, so this may not have been true back when it was asked. But, for what it's worth, there is a Scene type located in UnityEngine.SceneManagement. The SceneManager class appears to be able to do what you're looking for...

 using UnityEngine.SceneManagement;
 .
 .
 .
 Scene scene = SceneManager.GetSceneByName("Scene Name");

Hope this helps.

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
2

Answer by delstrega · Jul 03, 2012 at 02:19 PM

Actually there is a "scene type": EditorBuildSettingsScene. But its only available to editor scripts and only helps so much. But you can use this to add scenes to your build from script like shown here for example: http://answers.unity3d.com/questions/205742/adding-scene-to-build.html

Comment
Add comment · Show 2 · 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 Bunny83 · Jul 03, 2012 at 02:53 PM 0
Share

But EditorBuildSettingsScene actually just string with an additional boolean to specify if it's included or not. It's an internal helper class for the editor. It's also in the UnityEditor namespace, so it doesn't exist at runtime.

avatar image delstrega · Jul 03, 2012 at 04:01 PM 0
Share

That's why I said "it only helps so much" :)

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Load 3d models with code, possible? 2 Answers

how to get other script variable from other scene? 3 Answers

Load a scene/level when enemy is close... 1 Answer

How to load a scene on collision 1 Answer

Load Scene When... 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