2D Toolkit Forum
2D Toolkit => Support => Topic started by: cloudchen on November 12, 2013, 11:58:50 am
-
After updated to version 2.2.3, I've notice the log message
It is no longer necessary to hook up a camera to the tk2dUIManager. You can simply attach a tk2dUICamera script to the cameras that interact with UI.I would like to know is there any alternative way to get the pressed item which the tk2dUIManager originally kept? Thanks
-
The old method still works, just isn't necessary any more. You can ignore the message if you want.
-
I have noticed that If I attached the "tk2dUICamera" to my tk2dCamera, it will automatically created a tk2dUIManager object when the scene get launched. However, the UI Camera field did not been assigned any tk2dCamera.
So if I called tk2dUIManager.Instance.PressedItem.name under this situation, I always get NullReferenceException right?
-
No it shouldn't be. The uicamera field is null because it has another internal cameras List (instead of just one camera). You can have multiple cameras interacting with the UI, but everything else still behaves the same.
-
OK, actually I would like to use UIManager's "PressedItem" to help check if user touched on a UIItem to prevent some events been triggered.
So:
if (tk2dUIManager.Instance.PressedUIItem != null)
{
Debug.Log(tk2dUIManager.Instance.PressedUIItem.name);
shouldTriggerEvent = false;
}
these lines of code did work before I upgrade to version 2.2.3, but after that I got "NullReferenceException" when system called the Debug.Log line above. Have any idea about it?
-
Oh so now you don't have a tk2dUIManager, and this is null ref-ing? Isn't that the only thing that can be null there? Is there a uimanager in the scene at that point?
-
I check the existence of tk2dUIManager again, yes it's there. I've noticed that the NullReferenceException seems caused by the UIItem which are inherited from the previous scene via the DontDestroyOnLoad function. If I pressed the UIItem created in the current scene but not the previous one, everything works perfect!
-
I think you'll have to debug that to find out why the link is null - it shouldn't be if its DontDestroyOnLoaded, check that all the components on the object are sensible...