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
0
Question by Ecto-1 · Apr 30, 2014 at 09:40 AM · loadinglevelslevelload

Application.LoadLevel sometimes loads the wrong scene

So I have a project that has 4 Levels. If the player walks up-to an object and enters its collider, it asks the user to "Press - F". If the user presses F, they are taken to a hub where they can move around and, using the same process, select the next level they wish to enter. (Very reminiscent of Croc or Sly 1)

It was working absolutely fine. I wrote up a script that writes the name of the last levels exit point, so that the player will spawn at the right position close to the previous level in the hub and that works (I can see the names it writes to .txt and the player indeed spawns at the spawn-point with the same name, perfect)

But now, all of a sudden, it sometimes (80% of the time) WILL NOT load one of the levels.

I have 4 levels. 1) Start screen 2) Hub 3) Forrest 4) Lava

At start screen, pressing any key loads the Forrest level. The player can exit the Forrest level and return to the Hub level. The player can then chose to either go back to the Forrest level, or to go to the Lava level. But when the player presses F to load the Lava level, it simply loads the Forest level again.

The only time this isn't true, is when I load the Lava level in the inspector and start there instead of the Forest. Then for some reason It will work fine again, even if I start from any other level... But it breaks again the moment I save or export.

http://youtu.be/Y4ZVIgLpx1U

There's a video I made yesterday. IT WAS WORKING FINE.

The only thing I've changed in my code is from this code:

System.IO.File.WriteAllText("C:/Users/Ecto/Desktop/GAME DEV/Drake/DragonGame/Assets/Resources/SpawnPoint.txt", HubSpawnPoint);

to this code:

System.IO.File.WriteAllText(Application.dataPath + "/Resources/SpawnPoint.text", HubSpawnPoint);

Purely so that It will work when I export the level, but even If I change the code back to how it was, this glitch still happens.

PLEASE any help would be great. I hope that its just a stupid mistake that I missed.

Sometimes I get these 2 errors:

m_InstanceID == 0

PPtr cast failed when dereferencing! Casting from PlayerSettings to ProceduralMaterial!,

EDIT

http://puu.sh/8tjUa.png

http://puu.sh/8tiYt.png

HAHA!

Upon reading through the pictures I posted it seems that somewhere along the line I deleted the code that declares the collsion box! I put the code back and it seems tow work. Strange that it didnt throw a null as the box would have been undefined.

EDIT 2

The exported version still has the glitch.

EDIT 3

Changed the scripts so that nothing is public. Same problem. Im being told that sometimes Unity can skrew up its assets, hence the "m_InstanceID == 0" error I sometimes get... So I might have to start from scratch.

EDIT 4

Re-added all the scenes and even remade the scene in question from scratch. Same issue is still there. It works sometimes while other times it just does not.

 using UnityEngine;
 using System.Collections;
 
 public class LoadLevel: MonoBehaviour 
 {
     public string LevelToLoad;
     public string HubSpawnPoint;
     public string GuiText;
 
     public GameObject LoadArea;
     
     public bool CanLoad;
     
     void Start () 
     {
         CanLoad = false;
     }
 
     void OnTriggerEnter(Collider LoadArea) 
     {
         if (LoadArea.tag == "Player") 
         {
             CanLoad = true;
         }
     }
 
     void OnTriggerExit(Collider LoadArea) 
     {
         CanLoad = false;
     }
 
     void Update () 
     {
         if (Input.GetKeyDown("f") || Input.GetButtonDown("Fire1") && CanLoad == true)
         {
             System.IO.File.WriteAllText(Application.dataPath + "/Resources/SpawnPoint.text", HubSpawnPoint);
             Application.LoadLevel(LevelToLoad);
         }
     }
 
     void OnGUI()
     {
         if (CanLoad == true)
         {
             GUI.Label(new Rect((Screen.width /2), (Screen.height /2), 100, 100), ""+GuiText);
         }
     }
 }
Comment
Add comment · Show 4
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 KiraSensei · Apr 30, 2014 at 09:48 AM 0
Share

$$anonymous$$aybe you can post a screenshot of the build window to have a look at the scenes values you gave, and the different parts of code where you load the scenes.

avatar image Ecto-1 · Apr 30, 2014 at 09:57 AM 0
Share

Im simply using Application.LoadLevel(LevelToLoad); to load the level, where LevelToLoad is just a public string that is the same as the level name (And it is the same, its the first thing I checked) http://puu.sh/8tiYt.png

avatar image KiraSensei · Apr 30, 2014 at 01:55 PM 0
Share

So if LevelToLoad is public, it means that another script modify its value. Your problem may be in the others scripts that access this variable.

avatar image Ecto-1 · Apr 30, 2014 at 02:52 PM 0
Share

I was afraid that this would be the problem. Ive had trouble with it before when handling multiple instances of the same interactive object. Will change that and see how it comes along

This seems to work. Will test and see if it breaks.

Thanks for the help

Edit Still broken...

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

How to manage multiple levels in the 2D game ? 3 Answers

Level Loads properly in the editor but in the device builds when game is installed on machine. game quits instead of loading level 1 Answer

Way to load levels faster? 1 Answer

Need to alter script to load next level when level is completed 1 Answer

time between scenes (loading time) 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