Do keep mindful of any objects that may block the raycast! I had a canvas with components that I animated out of my screen, but they kept on blocking the raycast. I added "deactivate raycast target" at the end of the animation and solved the "mystery". Still, I must admit, I have gone bonkers until I finally realized what it was! DX
thanks for the video, when using this technique with UI toolkit in unity version 2021.3.24 i had the problem of not being able to select any game objects, only PanelSettings were being selected. i solved this by setting the picking mode of the root visual element to Ignore in the UI Builder
Great video, however, I would have loved it if you had explained how it would work with different objects with different actions, as I can't really see that function with how you show it in the example sadly.
I've set up the script and it works great, however I am trying to use this to inspect items but when I adjusted the main camera's near clipping plane, it no longer worked. Anyone know why?
Yeah sorry. It's a super sweet video and very to the point. But as a beginner I have no idea what I'm looking at what is from unity and what you wrote ahead of time. I can see that it's a super straight forward system once it's set up but I needed the "setting it up from zero" Thanks for the video though.
sorry but im having some problem with the clicking system rn. It keeps telling me that im having the error "CS0246:the type of namespace name... could not be found". Could you help me with this please?
okay so im using Cursor.lockState = CursorLockMode.Locked; because my game is in first person but this prevents being able to click on the object like this! Any way to fix it or workaround it?
There's some code in the Event System that prevents events if the cursor is locked if I remember correctly. There isn't an easy workaround, but you may be able to copy the script into a new file and make the necessary edits.
This is a great tip Andrew!. Thanks. It's been a while :-) I'd also like to know your take on custom graphic raycasters. Eg: Projecting a UI to a curved object (probably with render texture) and getting the raycast input to convert to a UI input. Mainly in VR
I haven't really created my own raycaster before. But, I'm pretty sure you can! I also have some experience with the Curved UI Asset. Technically, you may be able to use the existing Ray Interactor from XRI, a Custom Event System, and a visual element to bend the UI.
Hi! Thank you for great tip! However, as a beginner, I suffered a lot in implementing it. Could you please share or show in your tutorial MaterialApplier script :( In trying to make it on my own, I got completely lost
Can you please clarify how to select an object using a gamepad controller? I'm currently in the process of setting up my input systems for the gamepad, but I'm unsure of how to accomplish this task. Thank you for your assistance!
Are there any more resources on this? I just started my unity journey and cant quite get my head around this system. The Events seem to fire endlessly, not only when (for example) clicking on the GameObject I added this script too... No matter where I move/click the mouse. The script answers always.
Yeah, you can use the PointerEventData with some code like this. public override void OnPointerClick(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Right) { // Your code } }
Thought this would really easy but magically it's not working, followed the tutorial the exact same and followed other issued people have had but it's just simply not returning a debug on click at all
Do keep mindful of any objects that may block the raycast! I had a canvas with components that I animated out of my screen, but they kept on blocking the raycast. I added "deactivate raycast target" at the end of the animation and solved the "mystery". Still, I must admit, I have gone bonkers until I finally realized what it was! DX
Your comment just saved a lot of my gamejam time. Thank you!
Don't forget to add Box Collider component to your objects you want to click
deserves way more views and thumbs ups. thank you so much!
I needed this like 11 months ago ;)
Might go back and make that functionality more elegant
I'll know for next time! :)
thanks for the video,
when using this technique with UI toolkit in unity version 2021.3.24 i had the problem of not being able to select any game objects, only PanelSettings were being selected.
i solved this by setting the picking mode of the root visual element to Ignore in the UI Builder
3:47: go to definition, best thing I learned here woah
That's a really good Interactable objects approach!
Specially combined with UnityEvent
Thank you, and exactly! It's incredibly versatile.
This is so much better than using annoying raycasting. Thx so much!!1
Great video, however, I would have loved it if you had explained how it would work with different objects with different actions, as I can't really see that function with how you show it in the example sadly.
I've set up the script and it works great, however I am trying to use this to inspect items but when I adjusted the main camera's near clipping plane, it no longer worked. Anyone know why?
Thank you!
BTW, I had a problem with code generted mesh, it did not fire the events until you add collider (MeshCollider in my case), then it works.
Thanks! This resolved my issue. In my case I had to add a Box collider to my 3D game object
I had the exact same problem ... wish I saw this comment sooner : )
Great video. Elegant solution. Thank you!
Yeah sorry. It's a super sweet video and very to the point. But as a beginner I have no idea what I'm looking at what is from unity and what you wrote ahead of time. I can see that it's a super straight forward system once it's set up but I needed the "setting it up from zero" Thanks for the video though.
sorry but im having some problem with the clicking system rn. It keeps telling me that im having the error "CS0246:the type of namespace name... could not be found". Could you help me with this please?
okay so im using Cursor.lockState = CursorLockMode.Locked; because my game is in first person but this prevents being able to click on the object like this! Any way to fix it or workaround it?
There's some code in the Event System that prevents events if the cursor is locked if I remember correctly. There isn't an easy workaround, but you may be able to copy the script into a new file and make the necessary edits.
Very helpful, thank you 🙂
Happy to help!
This is a great tip Andrew!. Thanks. It's been a while :-)
I'd also like to know your take on custom graphic raycasters. Eg: Projecting a UI to a curved object (probably with render texture) and getting the raycast input to convert to a UI input. Mainly in VR
I haven't really created my own raycaster before. But, I'm pretty sure you can! I also have some experience with the Curved UI Asset. Technically, you may be able to use the existing Ray Interactor from XRI, a Custom Event System, and a visual element to bend the UI.
Hi! Thank you for great tip! However, as a beginner, I suffered a lot in implementing it. Could you please share or show in your tutorial MaterialApplier script :( In trying to make it on my own, I got completely lost
It's just a simple example script and not necessary for the implementation. You can easily just put debug statements instead.
Can you please clarify how to select an object using a gamepad controller? I'm currently in the process of setting up my input systems for the gamepad, but I'm unsure of how to accomplish this task. Thank you for your assistance!
Are there any more resources on this?
I just started my unity journey and cant quite get my head around this system.
The Events seem to fire endlessly, not only when (for example) clicking on the GameObject I added this script too...
No matter where I move/click the mouse. The script answers always.
Not exactly! However, feel free to join the Discord, and we'll see if we can figure it out.
@@VRwithAndrew I had to use a box collider! Today was a learn intensive day. Thank you :)
is there any way of implementig this with right clicks or does it only works with left clicks?
Yeah, you can use the PointerEventData with some code like this.
public override void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Right)
{
// Your code
}
}
thank you
Happy to help
Strange but I don't have Input System UI Input Module in my EventSystem, and I can't add it
Do you have the Input System Package installed?
@@VRwithAndrew oh I didn't input it, thanks
sorry but i have error on MaterialApplier. How to solve ?
That's just an example script. You can have a print statement there instead.
@@VRwithAndrew I just started with unity, how would I add the print statement?
@@DexterCrappell Within the click functions, you can write...
print("Click");
or
print("Hover");
Depending upon what the pointer event is
How can I
Thought this would really easy but magically it's not working, followed the tutorial the exact same and followed other issued people have had but it's just simply not returning a debug on click at all
Solution: Cursor.lockState isn't compatible with it. Pretty making this entirely useful except for a handful of cases, don't waste your time with this
This is not really helpful, you don't provide enough info
andrew tate , top g