2D Toolkit Forum

2D Toolkit => Support => Topic started by: pandaryll on August 21, 2013, 04:04:32 pm

Title: Reloading scene destroys UI camera of tk2dUIManager
Post by: pandaryll on August 21, 2013, 04:04:32 pm
Whenever I reload the scene using Application.LoadLevel(Application.loadedLevel) the UI camera of my Tk 2D UIManager becomes missing.

Here's the error message:
MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Camera.ScreenPointToRay (Vector3 position) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineCamera.cs:376)
tk2dUIManager.CheckInputs () (at Assets/TK2DROOT/tk2dUI/Code/Core/tk2dUIManager.cs:388)
tk2dUIManager.Update () (at Assets/TK2DROOT/tk2dUI/Code/Core/tk2dUIManager.cs:236)


The game will still run but the error persists.
Title: Re: Reloading scene destroys UI camera of tk2dUIManager
Post by: prodyminds on August 21, 2013, 04:31:54 pm
You can try creating a script and added to the camera with:

Code: [Select]
DontDestroyOnLoad (gameObject);
Maybe UIManager already has it, and lose the reference of the camera.
Title: Re: Reloading scene destroys UI camera of tk2dUIManager
Post by: unikronsoftware on August 21, 2013, 05:03:51 pm
What version of 2D Toolkit are you using?
Title: Re: Reloading scene destroys UI camera of tk2dUIManager
Post by: pandaryll on August 24, 2013, 06:18:36 pm
I'm using 2 final + hotfix 2 (taken from 2D Toolkit > About)

The camera isn't actually destroyed in the scene but somehow the UI manager loses it reference of it
Title: Re: Reloading scene destroys UI camera of tk2dUIManager
Post by: unikronsoftware on August 24, 2013, 09:00:00 pm
This is more complicated than it should be, but this has been sorted in the next release.
Do you have the tk2dUIAudioManager on the same object?

Whats happening is

tk2dUIManager -> camera1
when you reload, camera1 gets destroyed and recreated, but since uimanager is not destroyed, its still pointing to camera1.

The easiest way around this right now, is to simply assign camera1 to uimanager immediately after loading.
Title: Re: Reloading scene destroys UI camera of tk2dUIManager
Post by: pandaryll on August 25, 2013, 10:32:11 pm
that did the trick thanks!