How to: Virtual Mouse with Gamepad (Input System Unity Tutorial)

preview_player
Показать описание
👍 Learn to make awesome games step-by-step from start to finish.

🔴 RELATED VIDEOS 🔴

💬 Here's how to build a Virtual Mouse Cursor that you can control with a Gamepad!
Usually for menu controller support you have two options, making it jump from button to button (using Unity's Navigation system) or drive a virtual mouse cursor.
This is something I had to do for my game Dinky Guardians since I wanted it to be fully playable on a gamepad (or Steam Deck) and thankfully the Input System already supports this so it was pretty easy to implement.

📝 Some Links are Affiliate links which means it costs the same to you and I get a nice commission.
🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!

If you have any questions post them in the comments and I'll do my best to answer them.

See you next time!

#unitytutorial #unity3d #gamedev

--------------------------------------------------------------------
Hello and Welcome!
I'm your Code Monkey and here you will learn everything about Game Development in Unity using C#.

I've been developing games for several years with 8 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.

I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.

--------------------------------------------------------------------
- Other great Unity channels:
--------------------------------------------------------------------
Рекомендации по теме
Комментарии
Автор

💬 It's been a while since I made a regular tutorial, I hope it helps you!
👍 Learn to make awesome games step-by-step from start to finish.
🔴 RELATED VIDEOS 🔴

CodeMonkeyUnity
Автор

you made this video at the EXACT right time for me! I'm literally just starting to add controller support!

MrCrompz
Автор

CM never dissapoints! Great tutorial as always!

AndiTheDev
Автор

Very nice and thorough video! I always love seeing your journey as you use more packages.

I'd like to point out that there is a 'hardware cursor' cursor mode option on the virtual cursor component, that prevents double inputs for you from the get go!
Also, the cursor graphic checks for canvas in the hierarchy parents to limit the movement to that canvas's pixel rect. Scale indeed doesn't fully comply here.
Also, the event system component has a boolean to prevent sending navigation events as a whole. This can help too!

Yoraizr
Автор

Thank you for showing some of your Dinky Guardians code at the end. It helped me debug an issue with how I was detecting input device changes. Would have never thought to ignore the VirtualMouse inputs in that function.

tylrpage
Автор

While I absolutely despise the way AAA games are implementing this control scheme in all sorts of menus, I can appreciate a well done tutorial for it.. Good job!

skll
Автор

I had the exact same issues, as I guess the whole Unity community willing to use the Virtual Mouse component... at the version 1.7.X already.
Thanks a lot, this is a blast to have workaround-ers.

Laurent-mc
Автор

Wow, that's very useful, and it's nice that you not only explain how to implement the virtual mouse, but also the problems you came across! And indeed, I would expect a "production ready" package to have all of the bugs that you mentioned fixed. I mean, it's kidna ridiculous that apparently they didn't test canvas scaling and position going out of the screen...
But once again, thanks for the very insightful tutorial! (and for the time you spent going insane over those bugs)

DeiveEx
Автор

The perfect tutorial for this logic. Thank you for your time and love your work :)

BBFTW
Автор

Super usefull ... I was trying to do this kind of thing, and I didn't know that already exist a solution. Thank you.

mirkoemir
Автор

This tutorial helped a Ton! Thanks! I was having issue with navigating my ability tree UI with the automatic UI navigation.

dudley
Автор

Thanks for the video, it helps me about the Clamp problem! Actual you can fix the virtualMouse offset problem by setting the CanvasScaler-UIScaleMode to 'ConstantPixelSize', which will make the Canvas match exactly as the Game Window's size

threeyes_qiu
Автор

This is a very useful idea.

I was going to Google this out, for adapting my demo (from a PC port) to Mobile Platforms. By using the GamePad as the Mouse Pointer, everything is solved. 💯👌🏻

Thank You.

alec_almartson
Автор

YES. this is exactly what I needed when I needed it!

VyvyanTheGreat
Автор

I have a few questions to ask. First, did you use your own custom editor for your game? Second, I'm not quite sure what nameSpace and assembly definition are, but I'd like to know if I should use them. Third, what is a unit test and should I use it? Lastly, how can I determine my skill level when it comes to getting a job, such as which topics are considered beginner, intermediate, and advanced?

VastavPansuriya-xg
Автор

Watching this makes me wonder if anyone at Unity actually ever tested this feature... Thanks, Code Monkey, you saved me a LOT of headache!

Khud
Автор

Ok this tutorial saved my day. It was exactly what i needed. Thanks!

stephgamedev
Автор

i had to solve this problem several months ago, i mixed similar logic to this with your raycast from screen space to worldspace logic to recreate the 'hand' cursor from black & white in my clone called Ungodly.

UngodlyDev
Автор

Are you stalking me? I was just looking to make this for my game. Perfect timing!

Ironroc
Автор

When I move the joystick it auto selects a button but my button navigation is set to none. I also set move to none! so frustrating...

PeterMilko
join shbcf.ru