Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all 416 articles
Browse latest View live

"Dont destroy on load" does not work at forst

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class debugPlanePrefabController : MonoBehaviour { // Use this for initialization void Start () { DontDestroyOnLoad (this); } // Update is called once per frame void Update () { } } This script was working normally in Unity but I noticed that this script did not work on my phone(Debug). This gameobject destroyed. What code should I add? Or this problem is up to phone?

how to disable dontdestroyonload on a specific scene

$
0
0
hey, i'm making a 2d game that contains bonus scenes, so i manage to put my score to go over the scenes and don't destroy, so it would have the same value when the player went back to the main scene. here's the problem: when the player dies, the score does not reset. how can it make it reset when the player is dead? obs: the game over menu has a restart button and i tried to add something to his script, but it didn't work. the restart button script: public class LoadSceneOnClick : MonoBehaviour { public void LoadByIndex(int sceneIndex) { SceneManager.LoadScene (sceneIndex); } } the dontdestroyonload script: public class SaveScore : MonoBehaviour { void Awake () { DontDestroyOnLoad (this); if (FindObjectsOfType (GetType ()).Length > 1) { Destroy (gameObject); } } } thanks in advance c:

Do something at the end of every scene in a DontDestroyOnLoad object

$
0
0
I'm using Unity 5. I have an object with a bunch of scripts that is DontDestroyOnLoad. Is there a way to detect that the current scene is ending and to have the scripts on this object do something at the end of the scene? I have found some information on doing things at the start of the scene but I would like to do some cleanup before the scene ends. I am also unclear if this solution will work for a DontDestroyOnLoad object entering a new scene. https://forum.unity.com/threads/how-to-use-scenemanager-onsceneloaded.399221/

Canvas order and DontDestroyOnLoad

$
0
0
Hello! I have a problem with canvas order. I have 3 scenes in game. There are canvases with own UI elements on each scene plus canvas with common UI elements which put into DontDestroyOnLoad and jorney between scenes. All canvases has RenderMode=ScreenSpace-Overlay. So when scene is loading I have it's own canvas at the top in hierarchy and canvas in DontDestroyOnLoad at the bottom. I cant't have access to the common UI elements in DontDestroyOnLoad canvas because it fully overlayed with top-in-hierarchy canvas belonged to current scene. It seems that this problem wasn't in Unity 5.x because canvas at the bottom of hierarchy has highest priority. But it appear when I upgrade to 2017.x and it seems that now canvas at the top of hierarchy has highest priority. Is there any ways to solve this problem?

DontDestroyOnLoad for a specific scene

$
0
0
I have a scene called 'game'. And a gameobject. Every time the player selects the restart button, the game scene loads again. I don't want the gameobject to destroy when the game scene is loaded fresh. But when the player switches to the menu scene I want the gameobject to destroy. How can I do this? Thank you.

DontDestroyOnLoad Error with Firebase Analytics

$
0
0
Hi. I am trying to export a build to Android, but I get the following error: Error building Player: InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: Firebase Services. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script. I am using Firebase Analytics. I have tried cleaning the project of anything related to Firebase and reimported the newest version, but with no luck. Any ideas?

Objects remain under DontDestroyOnLoad despite being removed from the parent

$
0
0
I'm trying to upgrade a project from Unity 4.6 to 5.4 and I'm having an issue with objects not being removed when loading a new scene. I have a root game object which contains the player, camera, game manager, etc. and I use DontDestroyOnLoad to keep it when loading scenes. The player is able to pick up and drop/throw objects, which I do by parenting/unparenting the object to the player. But when I set an object's parent to null, the object stays under DontDestroyOnLoad in the hierarchy, so they remain after loading the next scene. I can see that Unity 5.4 shows the scene and DontDestroyOnLoad as two root items in the hierarchy, unlike 4.6. Is there a way to detach the child objects from the player and remove them from DontDestroyOnLoad? Do I actually need to parent them to some other root object?

Question Regarding Don'tDestroyOnLoad Object

$
0
0
Hi, I want to ask one thing, I have some objects that attached with the script of Don'tDestroyOnLoad scripts so that the objects will brought to other scene... But I want a certain scene to not have that don'tdestroyonload objects, so i have been searching and found the code working but the problem is once I return to that certain scene all the button at there won't work anymore like being stuck or being trampled by invisible panel so i can't touch anything... Here the code for one of my objects public class CameraCon : MonoBehaviour { public Transform target; public float mspeed; Camera mycam; private static bool camExists; public static int menuScreenBuildIndex; // Use this for initialization void Start () { DontDestroyOnLoad (transform.gameObject); mycam = GetComponent (); if(!camExists) { camExists = true; DontDestroyOnLoad (transform.gameObject); } else { Destroy (gameObject); } SceneManager.activeSceneChanged += DestroyOnMenuScreen; } // Update is called once per frame void Update () { if (target){ transform.position = Vector3.Lerp (transform.position, target.position, mspeed) + new Vector3 (0, 0, -10); } } void DestroyOnMenuScreen(Scene oldScene, Scene newScene) { if (newScene.buildIndex == menuScreenBuildIndex) { Destroy (gameObject); } } } I hope everyone can give me a solution on how to destroy the objects on certain scene For Example Case : I made an 2D RPG game with some objects that i don't want to destroyonload but I want to destroy it when I return to the main menu from pause and when I back to my game again, I want everything back to normal again like usual... (Probably might include saving or loading system that i still don't understand so much)

GameObject::scene and DontDestroyOnLoad()

$
0
0
Hi, If I assign a `GameObject` to the `DontDestroyOnLoad()` method and then call `print(gameObject.scene.name)` it prints out *"DontDestroyOnLoad"* instead of the scene name. Is there a way to get the scene in which the object was created after assigning it to `DontDestroyOnLoad()`? I know it can be done prior but I'm looking for a way to check after without storing a variable. Thanks,

How do you transfer UI Text from one scene to another?

$
0
0
The scoring of my game is based on how far the player travels on the x-axis. I use this code to calculate it: public Transform player; public Text scoreText; void Update() { scoreText.text = player.position.x.ToString("0"); } After the player collides with an object, they are sent to the *Game Over* scene. The problem is, I am not able to/ I don't know how to display the final score when they lose. I have tried using DontDestroyOnLoad and PlayerPrefs, but I couldn't get either of them to work with UI Text. Can someone help me?

How to get rid of the duplicates created by DontDestroyOnLoad?

$
0
0
I have a UI Text that gives a score based off of how far the player has traveled using this code: public Transform player; public Text scoreText; void Update() { scoreText.text = player.position.x.ToString("0"); } I want to display the value of scoreText on the *GameOver* scene that appears when the player collides with an obstacle. The way I am currently doing this is by using *DontDestroyOnLoad* with the following code: private void Awake() { DontDestroyOnLoad(gameObject); } This successfully takes the score and puts it on the next scene. However, when I press a *retry* button to take me back to the previous scene, I now have a duplicate of the score overlapping with the original. In other words, every time I play my game, I get a new copy of the score. _ Can someone help me find a way to prevent these duplicates from appearing every time I run the game? I only want the original score that keeps going up rather than the score from the last game.

lines after WaitForSeconds not executing if started the IEnumerator multiple times very quickly.

$
0
0
I have the below IEnumerator IEnumerator RemoveLine (string line) { Debug.Log("------------"); yield return new WaitForSeconds (1); Debug.Log("********"); drawLine.RemoveLine (line); } Now I have a Button Listener like below which just starts coroutine. public void Button() { StartCoroutine (RemoveLine(line)); } Now If I click the button 5 times the dashes are printed 5 times but star printed only once. Now I just Changed the button listener with the below function. public void Button() { LevelManager.Instance.StartCoroutine (RemoveLine(line)); } Where LevelManager is a dont destroy on load class. Now if I tap button 5 times, dash & star both printed 5 times. I'm getting confused with this weird behaviour. Does anyone have explanation?

Quality settings reset after scene loads

$
0
0
Hello! I have a settings menu with an option of changing graphics. When a player dies, the scene reloads. My problem is if the player switches graphics in the settings then dies, the graphics default to normal and not what the player wanted them to be at. How would I fix this? Thanks.

Instantiate a prefab in every scene

$
0
0
Guys, I am looking for a way to instantiate a prefab in every scene without neither putting gameobjects of it in editor nor another gameobject calling the instantiate. Any idea? The moral: I have a "Cheater" to test my game easily. I want to have it when I want to test the scenes individually via pressing run on a scene.

DontDestroyOnLoad not working in built project but work in editor

$
0
0
DontDestroyOnLoad not working in built project but work in editor.How can I solve it?

I am wondering how to save a int in the background

$
0
0
Hi, I have been trying to make an incremental game. I just started making it, but cant figure out how to save my score in the background. I have tried useing DontDestroyOnLoad(gameObject); , but this only returns with "DontDestroyOnLoad only work for root GameObjects or components on root GameObjects." I can not figure out how to fix this. I have some ide what roots are, but i dont know how it works. So my first question is what is the root? my second question is how do i save my score.(My game works with a button getting pressed, and a number going up. This nuber can go up for example 2 /sec) So i am wondering, how do i save this number in between scenes?

Can I create a scene DontDestroyOnLoad in editing mode??

$
0
0
I want some game object always exist in the game. Can I create a scene and the things which are in it don't be destroyed when I go to another scene. I have an idea but I wanna know if you guys have better method. Thanks in advance. the following is my method. 1.first create a scene and gameobject that you want them always exist. 2. create an empty gameobject and add the script. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class gamemanager : MonoBehaviour { void Awake() { foreach (GameObject a in FindObjectsOfType()) DontDestroyOnLoad(a); SceneManager.LoadScene(1); } }

dontdestroyonload scene being created on play? what is this and how do I get rid of it?

$
0
0
So I'm new to unity, so I'm not sure what is going on or the correct terminology but bear with me (please). I recently started a new game, everything was going fine, then all of a sudden I notice this new scene showing up when I press play play button tagged 'dontdestroyonload', and disappearing once playmode is exited. It was not there before, and I did not put it there (or at least I didn't intend to), and as such I'd like to remove it, however I don't know how to do that. I first noticed it when I was making a new script, which was suppose to give me information on my terrain (not that that worked), anyway so I deleted that script thinking it was the cause yet it persisted. I then deleted all but my terrain and it still persisted. After deleting only the terrain (either the terrain model or the terrain object, or both) and all my scripts it stopped showing up. I now figure it has something to do with the terrain, but what I don't know. anyway heres the script that started it all: (and that I deleted) using System.Collections; using System.Collections.Generic; using UnityEngine; public class test : MonoBehaviour { // Use this for initialization void Start () { Terrain terrain = GetComponent (); Debug.Log (terrain.terrainData); //note I have no clue what terrainData includes, i was just curious to what was inside } } Also here is an image to give you a better idea of what I am talking about: ![alt text][1] [1]: /storage/temp/112082-problem.png

DontDestroyOnLoad problem

$
0
0
Hi I'm trying to have a song start in Scene 1 and then continue through to Scene 2. But if Scene 3 happens, I want the audio to stop. I have Scene 1 to Scene 2 worked out. But for some reason I can't figure out how to stop the audio at Scene 3. With the code below, I have the game object in Scene 1 not being destroyed on load anywhere. And that LOST bool in the Update function comes from Scene 3. If it is true, then the Audio Source of the game object in Scene 1 should be false. But it just doesn't work. Any help would be great. Thanks! void Start() { GameObject.DontDestroyOnLoad (gameObject); loseCollider = GameObject.FindGameObjectWithTag ("LoseCollider"); } void Update() { if (loseCollider.GetComponent ().LOST == true) { this.GetComponent().enabled = false; } }

On Click Missing Audio Object when Scene changes

$
0
0
Not sure if this is a common problem, but it has been frustrating me for hours. I have a Main Menu. Two Buttons. Play and Exit I assign an on Click Event to the play an audio when clicked. ![alt text][1] The Audio Source is a GameObject that I have a Do Not Destroy on load script attached to it. When I change scenes and press by pressing play and and then change scenes again to come back to the main menu, the button loses the Game Object and says Missing Object. ![alt text][2] Why does this occur even though the Game Object is not destroyed. Is it a different instance of this Game Object or something and Unity can't see it anymore? [1]: /storage/temp/100195-button1.jpg [2]: /storage/temp/100196-buttonreload.jpg
Viewing all 416 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>