<RI> Input initialized.
<RI> Initialized touch support.
UnloadTime: 1.790000 ms
InControl (version 1.7.3 build 9338)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
(Filename: C:\buildslave\unity\build\Runtime/SceneManager/SceneManager.cpp Line: 559)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: <16314f843bce4f7b8ec1451f39891146> Line: 0)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: angry -> 4:(ಠ ∩ಠ)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: bar -> 1:————————————————————————————————————-
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: cheerful_flower_noanim -> 1:(◠-◠✿)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: drool -> 4:(º﹃º)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: happy -> 2:(⌒∇⌒)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: happy_flower -> 8:(◠-◠✿)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: laughing -> 2:(⌒▽⌒)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: nervous -> 2:(-﹏-。)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: party -> 1:⊙▽⊙
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: smug -> 2:( ̄^ ̄)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
Quick Element: surprise -> 2:⊙_⊙
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
— INPUT DEVICE CONNECTED —
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
— INPUT DEVICE CONNECTED —
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 48)
If it takes too long for them to reply im going to have to get a refund sadly, i cant afford having a game on my steam library i literally cant play.
Всем добрый день.
Возник вопрос.При запуске новой сцены «Настройки» пропадает музыка которая играла в самом меню.
Структура приложения есть абстрактный класс Sound.
Есть его дочерний класс MenuMusic
Так же есть GameObject с названием «MusicMainMenu» в котором только один компонент-AudioSource;
К нему прикреплен скрипт
When I’ve tried to use DontDestryOnLoad I get the error
DontDestroyOnLoad only work for root GameObjects or components on root
GameObjects. Is there another way to do this using your suggestion?
You have three options:
1.Set the parent of that child object to null then call DontDestroyOnLoad
on it. This will make the object not have a parent anymore so that DontDestroyOnLoad
will work on it:
public GameObject yourChildObj;
....
yourChildObj.transform.parent = null;
DontDestroyOnLoad(yourChildObj);
2.Call DontDestroyOnLoad
on the root of that object. Note that this will make the root object and its children live. You have to manually destroy other child objects and the parent after that since you only need that child object.
Get the root object of that child object. Get all the children under that root object except for that child object and store them in an array. Set the parent of that child object to null then call DontDestroyOnLoad
on that child object. Now, destroy the stored children and the parent.
public GameObject yourChildObj;
...
Transform root = yourChildObj.transform.root;
ClearChildren(root, yourChildObj.transform);
The ClearChildren
function:
public void ClearChildren(Transform targetRoot, Transform exclude)
{
Debug.Log(targetRoot.childCount);
int i = 0;
//Array to hold all child obj
GameObject[] allChildren = new GameObject[targetRoot.childCount];
//Find all child obj and store to that array
foreach (Transform child in targetRoot)
{
if (child != exclude)
{
allChildren[i] = child.gameObject;
i += 1;
}
}
//Remove exclude as the child
exclude.parent = null;
DontDestroyOnLoad(exclude);
//Now destroy them
foreach (GameObject child in allChildren)
{
if (child != null)
DestroyImmediate(child.gameObject);
}
//Now destroy the parent
if (targetRoot != null)
DestroyImmediate(targetRoot);
}
3.Use SceneManager.GetSceneByName
to move that Object to another scene that has been loaded.
Scene yourNexScene = SceneManager.GetSceneByName("SceneName");
SceneManager.MoveGameObjectToScene(yourChildObj, yourNexScene);
I prefer option 1 but if you need more objects in the-same root to leave then option 2 gives you chance to do that.
Edit
I completely missed this and assumed it was an issue with running DontDestroyOnLoad
, but your problem is that calling Instantiate clones the object, so when you call DontDestroyOnLoad
for your characters, you are calling it on Prefab Gameobjects which are not in the scene.
Solution:
- Create an array for your instantiated GameObjects with the length of the original characters array and is populated by the instantiated objects
- Call
DontDestroyOnLoad()
on THESE objects
private GameObject[] instantiatedCharacters;
...
void Awake(){
//For the GameManager
DontDestroyOnLoad(gameObject);
//Create array with correct length. This is not strictly necessary, but will be needed if you want to destroy the objects from here.
//This might need to go in Start()
instantiatedCharacters = new GameObject[characters.length];
}
...
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode){
if (scene.name == "Gameplay"){
//
instantiatedCharacters[CharIndex] = Instantiate(characters[CharIndex]);
//Dont Destroy the newly created objects
DontDestroyOnLoad(instantiatedCharacters[CharIndex]);
}
}
Original Answer:
Instance is uninitialized and will always be null on load. You need instance = this;
outside of the if statement in Awake()
Each time Awake() executes, you are calling Destroy(gameObject);
Edit:
Because the picture shows that the GameManager
class is on a separate objects and you are trying to preserve the characters, you need to call DontDestroyOnLoad
for each one.
void Awake(){
//For the GameManager
DontDestroyOnLoad(gameObject);
//For the Characters
for(int i = 0; i < characters.length; i++){
DontDestroyOnLoad(characters[i]);
}
}
После обновления, в котором убрали игровые помощники, игра начала крашиться на стадии загрузки в главное меню, выдавая ошибку Unity: «Drift Racing Online — Unity 2019.3.6f1_5c3fb0a11183»
Естественно, проблему попытался решить сам: проверял целостность файлов игры, переустанавливал игру, переустанавливал сам Unity — ничего не помогло.
Решил посмотреть, что пишет в логах:
Посмотрев обсуждения в стиме, понял, что не только у меня такая проблема, поэтому пишу сюда. ПОМОГИТЕ, ПОЖАЛУЙСТА!
When loading a new level, scene
, all Game Objects of the previous scene are destroyed by Unity.
If you want to protect a Game Object you can use the function.
DontDestroyOnLoad(gameObject);
It is important to note that when you say: this.gameObject
you are pointing to pretty much the same thing, it just happens that this
points directly to the script attached to that gameObject. So you don’t need the this
part, just gameObject
will do.
Ideally you could protect that gameObject inside void Awake()
void Awake()
{
DontDestroyOnLoad(gameObject);
}
The above code will prevent Unity from destroying that gameObject unless your game closes completely or at a later point you call Destroy()
on it. That means you can change from scene to scene and the gameObject will survive. However, if you make it back to the scene that creates that gameObject you are protecting you may run into problems if you do not have the logic implemented that prevents you from protecting a second, third, or many of that gameObject.
Your second question, if I understand it correctly:
You want to send mail when you change scenes, but your progress bar wont progress while changing scenes, it just stays there, static.
If that is the case then your problem is in Application.LoadLevel(sceneName);
If you have the free version of Unity, then you need to come up with your own creative way of showing that progress bar, because Application.LoadLevel()
will halt everything until it takes you to the new scene.