- Home /
Resetting a Level from within itself
We are having problems loading a level with Application.LoadLevel("levelName"); if that level has been previously loaded already. Particle systems don't play (although I can see them in the inspector), as well as animations.
Is there some other function for loading a level that really and truly loads a "pure" level as though it has never been played? It seems like Application.LoadLevel("name"); also does some destructive things as it "unloads" the current level that permanently changes settings in that level during one playthrough.
EDIT:
I have begun working on a test case to see if I can get a repro.
I created an empty scene, and created a particle system in that scene. I didn't edit any settings in the particle emitter component. I created a new animation for that particle system in which it moves up and down out of view for a few seconds, and then loops back around.
I created this script, and attached it to an empty game object. This scripts reloads a specified level after the timer runs out. In my level, I have set the "Level To Load" as the current level.
using UnityEngine;
using System.Collections;
[System.Serializable] public class Test_Loader : MonoBehaviour {
public string levelToLoad;
public float timerDuration;
private float timer;
// Use this for initialization
void Start () {
timer = timerDuration;
Debug.Log("Timer = " + timer);
}
// Update is called once per frame
void Update () {
timer -= Time.fixedDeltaTime;
if(timer <= 0)
loadLevel(levelToLoad);
}
public void loadLevel(string level)
{
Debug.Log("Loading " + levelToLoad);
Application.LoadLevel(level);
}
}
So far, everything works as expected. I am now going to modify this script to trigger the animation to play on level load, and remove the looping wrapping and the play automatically flags.
No. But even if I were it wouldn't matter. It's not just particles. It's animations as well. Both imported and motion tracked. Application.LoadLevel is doing something as it unloads the current level and loads the requested one that doesn't get reset if that unloaded level is then loaded via the same call.
I understand your frustration. I only ask because I'm trying to recreate your problem as close as possible, which I have not experienced myself.
Yeah, I'm sorry. I'm so used to people "answering" questions without actually reading the question. I just sort of expect it. You're right though, I should demonstrate some repro. Let me work on a simple test case and post it here.
Answer by aVittone · Mar 05, 2012 at 09:49 PM
I figured it out.
I was loading the levels from within a menu that set Time.timescale = 0 when it was visible (to pause the game).
Well, Time.TimeScale never got reset to 1. Hah. In my loadlevel function (that calls application.loadlevel, among other things) I set timescale back to 1 for happy fun times.
I had that same issue earlier in one of my games actually, not sure why I didn't think to mention it. Glad you got it solved!
Your answer
Follow this Question
Related Questions
Starting/Triggering events based on hover time 0 Answers
reset the level? 5 Answers
Reset The Scene ? 2 Answers
How can I restart a single-scene game? 1 Answer
"Reset Level", Application.LoadLevel 1 Answer