- Home /
Self Answered
Where did EventSystem.GetCurrentPointerData go?
I remember I was able to get last raycast info from the new eventsystem when it was in beta version. Now I can't find how to do it. Is this functionality removed in 4.6 release?
I want this to avoid to make an additional raycast to the scene. Since EventSystem is already making a raycast via PhysicsRaycaster component, I should be able to reach its cached data without making another raycast. Right?
Can you guys remember how to do this?
--EDIT--
After some search in my SVN repository, I found this old code piece which worked very well in 4.6 beta... I was trying to simulate MouseMove events which is the same behavior that I want to achieve now :)
I also updated the title of the question.
in Update event:
// Simulate MouseMove event
/*
var PointerData = EventSystem.instance.GetCurrentPointerData().FirstOrDefault();
if (PointerData != null && PointerData.pointerEnter == gameObject)
{
if (Input.mousePosition != LastMousePosition)
{
SendMouseMoveEvent();
LastMousePosition = Input.mousePosition;
}
}
else LastMousePosition = -Vector3.one;
*/
You can implement this yourself. Just store the hitinfo after you make the raycast :) Sorry, it doesnt mention the EventSystem but I like to cheat at program$$anonymous$$g.
It's not about cheating program$$anonymous$$g or not. As I mentioned in the question, I don't want to make a redundant raycast because EventSystem already does one. Its data was accessible in 4.6 beta.
Ok I see, the hitinfo doesnt appear to be exposed in the above.
Do you remember what the calls looked like before?
The only trace I can find is that lastHit is a member of NGUI's UICamera.
What data is it you would like to retrieve, specifically?
http://docs.unity3d.com/ScriptReference/EventSystems.RaycastResult.html
Unfortunately I can't :(
$$anonymous$$aybe it was something like EventSystem.current.getLastsomething something. I hate my self because I lost that example code in my library.
YESS!!!! I found the beta test code from old SVN commits. I love SVN :)
I'll update my question with the old code...
Answer by Xtro · Feb 09, 2015 at 09:16 PM
Now I found out that StandaloneInputModule class has GetMousePointerEventData method but it's protected. Maybe I can inherit that class to be able to access the GetMousePointerEventData method...
--EDIT--
I solved my problem by inheriting the standalone input class.
public class CustomStandaloneInputModule : StandaloneInputModule
{
public PointerEventData GetPointerData()
{
return m_PointerData[kMouseLeftId];
}
}
Now I can attach this custom component onto EventSystem gameobject instead of standalone component and I can call GetPointerData method on it.
var StandaloneInputModule = (CustomStandaloneInputModule)EventSystem.current.currentInputModule;
print(StandaloneInputModule.GetPointerData().pointerEnter);
It works and I can get the gameobject which mouse pointer hovers over... :)
I definitely would prefer that standalone input class would have GetPointerData implemented as public.
Does Pointer Event Data have what you need? This is used by both the Touch and Standalone modules.
PointerInput$$anonymous$$odule actually has a bunch of cached information, current and last.
$$anonymous$$ost of them are protected. I inherited the Standalone input class and solved my problem. I'll update my answer.
i tried this, trying to debug log the " Debug.Log(StandaloneInput$$anonymous$$odule.GetPointerData().pointerPress);"
from another class but nothing is happening, can anyone help?
I get InvalidCastException.
Custom$$anonymous$$odule custom$$anonymous$$odule = (Custom$$anonymous$$odule) EventSystem.current.currentInput$$anonymous$$odule;
I posted this long time ago and Unity API might have been changed. Are you sure you inherited your Custom$$anonymous$$odule class from StandaloneInput$$anonymous$$odule class?
Having the same problem too, it appears that this method no longer works.
$$anonymous$$e too. I would appreciate if someone else that found a solution to this could share it!
Follow this Question
Related Questions
understand how "Raycast Target" works on UI elements 2 Answers
TMPro UI elements not blocking raycasts 2 Answers
Help, Use event system IPointerClickHandler 1 Answer
Unity 4.6 UI - Ignore raycast -1 Answers
How do you perform a Graphic Raycast? 3 Answers