Hello Guest

Author Topic: Reloading scene destroys UI camera of tk2dUIManager  (Read 5092 times)

pandaryll

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Reloading scene destroys UI camera of tk2dUIManager
« 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.

prodyminds

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Reloading scene destroys UI camera of tk2dUIManager
« Reply #1 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Reloading scene destroys UI camera of tk2dUIManager
« Reply #2 on: August 21, 2013, 05:03:51 pm »
What version of 2D Toolkit are you using?

pandaryll

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Reloading scene destroys UI camera of tk2dUIManager
« Reply #3 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
« Last Edit: August 24, 2013, 06:21:27 pm by pandaryll »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Reloading scene destroys UI camera of tk2dUIManager
« Reply #4 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.

pandaryll

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Reloading scene destroys UI camera of tk2dUIManager
« Reply #5 on: August 25, 2013, 10:32:11 pm »
that did the trick thanks!