SetNonUIHitDelegate Not Working?

Re: SetNonUIHitDelegate Not Working?

Postby Malveka » Mon Feb 21, 2011 10:14 pm

I think it's misspelled. Try DidPionterHitUI().

Cheers,
Mal
Malveka
 
Posts: 152
Joined: Sun Jul 11, 2010 1:56 am

Re: SetNonUIHitDelegate Not Working?

Postby Brady » Mon Feb 21, 2011 10:47 pm

Argh, that's awful! Sorry about that. This will be fixed in 1.056.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: SetNonUIHitDelegate Not Working?

Postby trojanlw » Tue Feb 22, 2011 9:09 pm

Cool, that worked. Thanks
trojanlw
 
Posts: 4
Joined: Mon Feb 21, 2011 1:13 pm

Re: SetNonUIHitDelegate Not Working?

Postby John B » Wed Mar 16, 2011 12:07 am

I just started a new project and again can't get SetNonUIHitDelegate to work. Even though my scene is full of colliders, it never calls the delegate function no matter where I click. Is there some camera setting that I might not have set correctly? I have two cameras besides the GUI camera for two different views of the scene, but no hits are caught when either one is enabled. Or maybe some UIManager setting?

FWIW, once when I was clicking all over the screen, the delegate got called once. I don't know what that means, other than my code is correct. I never was able to get it to fire again.
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

Re: SetNonUIHitDelegate Not Working?

Postby Brady » Wed Mar 16, 2011 12:33 am

Did you make sure the objects in question are in a layer that is not being masked out by the mask setting in the UI Cameras array? Also check that the depth is set deep enough into the scene to "reach" the objects (defaults to infinity).
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: SetNonUIHitDelegate Not Working?

Postby John B » Wed Mar 16, 2011 1:13 am

I had both the UI camera's culling mask layers and the camera mask setting in the UIManager set to only the GUI layer. But it doesn't matter. Even if I set both masks to everything, I'm still not getting any hits. Depth is at infinity.

Interesting, if I turn off all camera's except the UI camera and set the UI camera's culling mask to everything, I cannot see any of the objects in the scene. Shouldn't the UI camera see the objects in the scene if it is seeing all layers? The scene objects are right in front of the UI camera.
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

Re: SetNonUIHitDelegate Not Working?

Postby Brady » Wed Mar 16, 2011 7:02 am

Yes, it should see them if they're within the frustum (make sure they aren't so near as to be just behind the near plane). If it can't see the objects, then it sounds like this may be a clue to, or related to, the underlying problem. For the moment, however, I can't think of a reason why a camera, which is pointed at some objects and has its culling mask set to "Everything" would fail to render those objects.

Also, one other thing to check (which doesn't have anything to do with the rendering, just EZ GUI detecting hits) would be to look in your physics settings (Edit->Project Settings->Physics) and see if "Raycasts Hit Triggers" is checked. This needs to be enabled for EZ GUI to detect "hits" against colliders marked as triggers.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: SetNonUIHitDelegate Not Working?

Postby John B » Tue Jul 12, 2011 9:54 pm

I'm just updating another older project and still having trouble with SetNonUIHitDelegate. This time I want to use it "correctly," to identify when a rigidbody is clicked. I have several rigidbodies with colliders attached (do I need colliders?). It used to work before updating, but now it doesn't. I set the delegate, then on a hit check to see which rigid body was hit. But now the delegate is not firing at all no matter what is clicked.

I only have two cameras, the main camera for the 3D stuff and the GUI camera. The rigidbodies are in the main camera's culling mask layer, but it makes no difference if they are in the GUI layer. I've tried AddNonUIHitDelegate with the same result. I also tried AddMouseTouchPtrListener, but it always registers more than one hit on an object (I guess because the mouse is held down for more than one update loop). In this case I can only have a single hit at a time as the click is used to select/unselect objects.

On Start:

UIManager.instance.SetNonUIHitDelegate(ClickDispatch);

Then the delegate:

function ClickDispatch (ptr: POINTER_INFO) {
Debug.Log("hit");
// check to see what was hit
}

Any ideas?

Just wondering, could this have something to do with the main camera only occupying the top half of the screen -- normalized viewport rect Y = 0.5? To answer my own question, no, it still doesn't work if I set Y back to 1.
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

Re: SetNonUIHitDelegate Not Working?

Postby Brady » Tue Jul 12, 2011 10:14 pm

One thing to remember is that EZ GUI doesn't filter hit tests using the camera's own culling mask, since it is not uncommon that you would want things rendered by the camera that you don't want to be tested as part of the UI. So you have to set the mask you want to use for the UI separately in the UIManager's "UI Cameras" array. This is set per-camera. So I suppose it's possible that that specific camera may be masking out the layer the objects are in.

Also, yes, the objects must have colliders or else there's nothing to test against.

The requirements for a non-UI hit to be registered are:
* The object must be in front of a camera listed in the UIManager's "UI Cameras" array.
* The camera(s) in question must have, in its "UI Cameras" array entry, its mask set to include the layer the object is in.
* The object in question must not bear any EZ GUI control components (UIButton, etc,) or else it will be recognized as a UI hit.
* The object must have a collider.
* Then finally, the user must move a pointer over, or tap on, the object in question, causing the non-UI hit to be recognized. If a delegate has been registered via SetNonUIHitDelegate(), then if all the foregoing are done, your delegate should get called with the pointer information of the pointer which hit the non-UI object.

Let me know if none of that helps.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: SetNonUIHitDelegate Not Working?

Postby John B » Wed Jul 13, 2011 12:26 am

All of the requirements you listed are met, and it still doesn't work. Even setting the UI Camera's mask to everything makes no difference.

However, adding a second camera to the UI Cameras array makes it work. Sort of. It's registering multiple hits for each click. It never did that before. So I had to check for the type of event, and return if it's not PRESS. But I'm not sure how to code that enum variable. I ended up with the following, but I'm pretty sure that's not the best way to do it:

if (ptr.evt != 1)
return;
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

PreviousNext

Return to EZ GUI General

Who is online

Users browsing this forum: BobbyMam and 5 guests

cron