0

I have an interactable ground like a network of hexagon tiles in my project. I am using a new UI system from Unity, UI toolkit, and clicking a UI button makes Raycast go through and interact with the tile below.

I read about some dirty solutions, but I believe there is a better solution than these: https://forum.unity.com/threads/ui-toolkit-and-raycast-block.1034938/#post-8218593

In old UI system was something like EventSystem.current.IsPointerOverGameObject

Can anyone help me?

Wolfik
  • 286
  • 2
  • 7
  • 22

2 Answers2

0

Is the clicked button working? If not you are probably missing raycast target. Make sure it is set to true on your button's image. If that's not the case you could try using:

UnityEngine.Event.current.Use();

in your buttons callback to consume the event and stop further execution.

  • Yeah, button is working properly. This is my first project on UI Builder, so thanks for your advice, I will try it. – Wolfik Jun 26 '22 at 08:00
  • No, its not working, probably because it's new UI system, not old. "NullReferenceException: Object reference not set to an instance of an object" – Wolfik Jun 26 '22 at 11:23
0

I found the way to make EventSystem.current.IsPointerOverGameObject work.

I had a big #Screen VisualElement streching the whole screen. In the UI builder there is a property named PickingMode under the first inspector section. You just set it to ignore and it will not be detected.

If you want to check individual elements, I have no solution for that, but there is a method .Pick(Vector2) and I don't know how it works yet.

https://docs.unity3d.com/Manual/UIE-faq-event-and-input-system.html

User2187
  • 1
  • 1
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32907322) – Bemn Oct 14 '22 at 10:23