SOLVED! Game input events, ray cast and UI input events

Good evening. I am currently making a simple RTS game where most of the selections are made (units, structures,…) are made via a PlayerController (script) using ray casts and mouse events. However I can not find a way to filter similar mouse press events when the mouse is over my UI. They are always forwarded to the player and not filtered/captured by the UI. Is there a way to filter (stop) events when the mouse is over UI Canvas and processed by the UI?

1 Like

Game scripts can separate UI usage and gameplay where user uses mouse for camera controls/picking.
For RTS-style game with UI mixed with world objects I would use custom UI plugged into RootControl.GameRoot to gather input events (instead of global Input). This would handle UICanvas gathering input first if over the top of the custom control.

Thank you for your reply.
What I did, was to first detect if the UICanvas had any focus. Also in the child UIControl that should take the focus, I set the UIControl’s Control.AutoFocus = true;

// In playercontroller script all the selections are made.
public override void OnUpdate()
{
// if the GUI or any child on the UICanvas has the focus, return
if (hudCanvas && hudCanvas.GUI.ContainsFocus)
return;

world object selections…
}

I will also, try to follow your advice and put all the input related into the custom UICanvas.