Custom Cursor with Input System - Unity Tutorial

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 86

  • @eamartig
    @eamartig 4 роки тому +20

    This channel is so underrated. This is easily the best Unity tutorial channel for beginners on UA-cam.

    • @samyam
      @samyam  4 роки тому +2

      Glad you like it :)!

    • @brainwavestobinary
      @brainwavestobinary 4 роки тому +1

      I agree. Cool thing is that the channel has more than doubled subscribers in the last 30 days (according to SocialBlade), so people are noticing. Hopefully it keeps up.

    • @samyam
      @samyam  4 роки тому +1

      Thank you! 😁

  • @BarcelonaMove
    @BarcelonaMove 2 роки тому +2

    I love how she moves the mouse around the thing while explaining it. It shows a lot of enthusiasm about the topic.

    • @samyam
      @samyam  2 роки тому

      Some people were complaining about it so I’ve stopped doing it as much in my more recent videos 🤣 Glad someone liked it!

  • @MasonWolf90
    @MasonWolf90 3 місяці тому

    Thanks! I have watched so many different videos and none of them worked, but this video was straight to the point.

  • @CrunchyClub2020
    @CrunchyClub2020 3 роки тому +3

    If you get a "Can't add script error" it's because line 5 of the code after "public class" needs to be the same name as whatever the script is. This is my second day of unity and I renamed the script after I made it so the names didn't match. Awesome video, thanks for NOT including 10 minutes of fluffy BS.

  • @moandtell
    @moandtell 3 роки тому +1

    Thank you so much for this video! I've learned so much in just the first half alone! This is my first step to building a game, and it feels really good to see something actually working when I press play!

  • @anaribeiro9471
    @anaribeiro9471 3 роки тому +1

    This is the best tutorials I have seen for UNITY. Well done! And thank you so much for this great content.

    • @samyam
      @samyam  3 роки тому

      Thank you!! 😄

  • @uhhhhh2672
    @uhhhhh2672 Рік тому +2

    If you get an error message like me that says "`Cursor' does not contain a definition for `SetCursor'" its because you named your script "Cursor". Was banging my head against the wall trying to figure it out. Dont be like me, name your script appropriately lmao

    • @ceciliacecchet5869
      @ceciliacecchet5869 Рік тому

      same here, but I named the input control "cursor"

    • @pineneedle116
      @pineneedle116 5 місяців тому

      I did neither of these and am having the same issue?

  • @mantavisions2362
    @mantavisions2362 2 роки тому

    THANK YOU! this saved me, i was struggling! haha

  • @georgigeorgiev5524
    @georgigeorgiev5524 2 роки тому

    Thank you so much I needed this type of tutorial =D

  • @angiemon897
    @angiemon897 10 днів тому

    How do I make the cursor scale correctly with different resolutions? :(

  • @starwarsfan6868
    @starwarsfan6868 2 роки тому

    Thank u so much for this video!!! It helps soooo much! You're really a good teacher!!!

    • @samyam
      @samyam  2 роки тому

      Thank you so much!! Appreciate it 😁

    • @starwarsfan6868
      @starwarsfan6868 2 роки тому

      The click doesnt work by me. There are no errors, but it just doesnt work! Any ideas why???

  • @kamranbigdely
    @kamranbigdely 2 роки тому +1

    Thanks!

    • @samyam
      @samyam  2 роки тому

      Thanks so much for the donation!! :D

  • @vinipossatto9586
    @vinipossatto9586 4 роки тому +1

    Nice video!

  • @grimonmilk7287
    @grimonmilk7287 2 роки тому

    I get this error code when I try this "Assets\Pixel Cursors\CursorController.cs(24,6): error CS1513: } expected"

  • @chloefinlay9133
    @chloefinlay9133 3 роки тому +1

    This is such a great and clear tutorial! I'm just wondering (as I am new to unity) if there's a way I can use this method to click my objects but also use the mouse to look around the environment also? Thank you for any help you can give :)

    • @samyam
      @samyam  3 роки тому +1

      Awesome! Yes I have a follow up video for clicking
      ua-cam.com/video/JID7YaHAtKA/v-deo.html
      and I have a video on panning and zooming around the scene with cinemachine
      ua-cam.com/video/PsAbHoB85hM/v-deo.html
      And then if you want to bound your camera movement to a certain space here is another video
      ua-cam.com/video/izumXk-xoEM/v-deo.html
      Lots of videos 😂

    • @chloefinlay9133
      @chloefinlay9133 3 роки тому

      @@samyam Thank you so so much!

  • @rbanister100
    @rbanister100 3 роки тому +1

    the buDIN, as opposed to button

  • @kaloshabuthapa3284
    @kaloshabuthapa3284 2 роки тому +1

    When writing script, for start function, 7:47, controls.Mouse.Click.started, my script has error: “CursorControl does not contain a definition for “Mouse” . There was an option for MouseActionMap, are they the same ? How to fix this error?

    • @Klash120
      @Klash120 2 роки тому

      I'm stuck at that part too :x

    • @Klash120
      @Klash120 2 роки тому

      Figured it out right as I left a comment! I was using my own naming for variables & such, User error! If you've done the same, check your input action naming. Name of variable you've set (control), Action Map name (mouse), and Action (Click). Control.mouse.click; If you use the default mapping that Unity makes, it'll be [your variable name].Player.click. Hope that helps~

    • @camillatomasetti2453
      @camillatomasetti2453 3 місяці тому

      ​@@Klash120 i have the same problem, but I don't quite understand what do you mean 😅 can you try to explaine better? Thank you!

  • @alphaanar2651
    @alphaanar2651 4 роки тому +2

    YAY! new video that explains stuff which l have no idea what is this :D

  • @jianingzhuang104
    @jianingzhuang104 3 роки тому +1

    Nice video! May I ask if we can resize the cursor using script? Thanks.

    • @samyam
      @samyam  3 роки тому

      32x32 texture for cursor is required, however according to this forum you can possibly resize the actual pixels of the texture:
      forum.unity.com/threads/cursor-size.288333/#:~:text=If%20you%20want%20to%20resize,is%20just%20taking%20up%20memory.
      Or you can ignore this method and have an empty gameobject with a sprite cursor and have that follow your mouse movement

    • @jianingzhuang104
      @jianingzhuang104 3 роки тому

      @@samyam Thank you very much!

  • @louisburden4371
    @louisburden4371 2 роки тому

    My imported cursor only appears once I hit escape. Any ideas?

  • @klause2s
    @klause2s Рік тому

    i have been informed by unity that "'Texture2D' does not contain a definition for 'SetCursor' and no accessible extension method 'SetCursor' accepting a first argument of type 'Texture2D' could be found (are you missing a using directive or an assembly reference?)"
    can you provide assistance? would be appreciated

    • @carterlynch2669
      @carterlynch2669 11 місяців тому

      Same issue, don't know how to fix it. Did you find a solution

    • @klause2s
      @klause2s 11 місяців тому

      i have not, i've since moved away from unity and toward gamemaker

  • @roland_art
    @roland_art 4 роки тому

    Useful, thanks! If I can, how change (overlay) the color of cursor with c# script?

    • @samyam
      @samyam  4 роки тому

      You could either take in another texture with the color you want or you'd have to change the color by going through each pixel of the texture 2d and changing the tint.
      gamedev.stackexchange.com/questions/124463/changing-some-color-of-a-texture-using-c-in-unity
      If you only have a mouse in your GUI you can apply a global GUI tint to change the color at that moment
      forum.unity.com/threads/dynamical-color-change-of-mouse-pointer.166366/

    • @roland_art
      @roland_art 4 роки тому

      @@samyam Thank you!

  • @vladimirgalkin412
    @vladimirgalkin412 3 роки тому

    Please. how to add trail effect on mouse cursor?

    • @samyam
      @samyam  3 роки тому

      I show how to do a similar effect here: ua-cam.com/video/XUx_QlJpd0M/v-deo.html
      Basically add the trail renderer to a gameobject, then move the gameobject according to where the mouse is

  • @fernandomilans8444
    @fernandomilans8444 4 роки тому

    hi, i was thinking of changing my project's implementation of inputs to 'input system', but is it worth it?
    I say, 'input system' is in version 1.0, so I imagine there will be annoying bugs, I saw the documentation but I do not realize the great advantages over doing it the 'traditional' way.
    What is your opinion at the time of practice, what 'great advantages' you see in 'input system'.
    Thanks, and very good videos, greetings!

    • @samyam
      @samyam  4 роки тому

      I recommend it, super simple to set up and you can easily change controls for different systems as well as allow multiple controls for one action.

  • @fluorescente
    @fluorescente 2 роки тому

    silly question here but... how to make a 3D object automatically rotating like an idle state?

    • @samyam
      @samyam  2 роки тому +1

      so rotate around the y axis? In the update method you can call RotateAround similar to the example here docs.unity3d.com/ScriptReference/Transform.RotateAround.html

    • @fluorescente
      @fluorescente 2 роки тому

      @@samyam thank you! I knew it had to be easy! I'm just new to Unity ^_^

  • @functionSam
    @functionSam 3 роки тому

    For using a mouse cursor in a menu system, would "release only" be suitable? I'm trying to create a mouse interaction that feels "natural" (at least in a menu to start)

    • @samyam
      @samyam  3 роки тому

      Yes I think release would be suitable, you can always test or ask someone to test to see how it feels.

  • @UnGaming-eh7ht
    @UnGaming-eh7ht 4 роки тому

    Honestly curious what color theme you're using for vs code here

    • @samyam
      @samyam  4 роки тому

      I'm using the Godot color theme 😂

  • @iamnotcreativeenoughforana5875
    @iamnotcreativeenoughforana5875 3 роки тому

    Can anyone help me? I'm trying to lock the cursor in the middle of the screen with having it stay visible, is there a way to do this?

    • @samyam
      @samyam  3 роки тому +1

      Hm why would you want to do this? It’ll make the player feel as if they can’t move the mouse. To lock it in the middle you can use Cursor.lockState = CursorLockMode.Locked;
      And if you want something to show in the middle you can add a sprite to the center of the screen

  • @t33h33studio
    @t33h33studio 3 місяці тому

    Unfortunately, SetCursor is unusable for me. At first I thought I made a bug, but SetCursor simply does not change my cursor at times. I am not alone in this issue as people have stated this function to be unreliable for years. The OS wants to fight Unity for control.

  • @SankalpParab
    @SankalpParab 3 роки тому

    how to interact with world space ui in cursor lock mode

    • @samyam
      @samyam  3 роки тому +1

      That’s a little tricky it seems, you’ll have to simulate the mouse cursor if you lock it to see what UI it is over. You can also shoot raycasts and have the UI with colliders to detect if the ray hits the button.
      Here’s some threads that may help
      forum.unity.com/threads/world-space-canvas-cursorlockmode-locked-incompatible.566485/
      forum.unity.com/threads/fake-mouse-position-in-4-6-ui-answered.283748/?_ga=2.160872958.255425762.1618484813-653284547.1617361468
      stackoverflow.com/questions/38054706/alternative-of-raycast-for-ui-items-in-unity3d
      stackoverflow.com/questions/42384658/unity-ui-interacting-with-worldspace-ui-when-cursor-is-locked

    • @SankalpParab
      @SankalpParab 3 роки тому +1

      @@samyam thank you so much for your suggestions ✌🏻😇

  • @animationspace8550
    @animationspace8550 4 роки тому

    Unity says I have no definition for "SetCursor" or "lockState"
    can you help out or let me have a finished scripted (my code barely comes out right)

    • @samyam
      @samyam  4 роки тому

      Make sure you are putting Cursor.SetCursor and Cursor.lockState. The code is available for patrons in the description.

    • @HadiExtreme
      @HadiExtreme 4 роки тому +1

      Oh I had this problem last month! If you haven't solved it already, check your script name. If you named it Cursor, then it would be overriding Unity's Cursor class, causing the problem.

    • @CodeWithMilk
      @CodeWithMilk 2 роки тому

      @@HadiExtreme It was the excatly problem I had... thx!

  • @kaydnshepard8131
    @kaydnshepard8131 3 роки тому +1

    I changed this Input System and my whole Game crashed. Now reinstalling Unity and hope that I can fix this =/ but anyway I learned how to change my curser.

    • @samyam
      @samyam  3 роки тому

      😅 remember to back up your project!

    • @kaydnshepard8131
      @kaydnshepard8131 3 роки тому

      @@samyam yeah sure 😋, lesson learned. But I will see it as a second chance to start my game new with better codes and graphics. I was not that far with the game 🖖🏼

  • @crusader1910
    @crusader1910 4 роки тому

    My cursor is only pixels or a disstroted image. Any idea why?

    • @samyam
      @samyam  4 роки тому

      It has to do with your import settings on the image. Make sure it is set to Texture2D for type and you can adjust the compression and filtering as well

  • @OutCold9te6
    @OutCold9te6 3 роки тому

    I tried this with a new 2d sprite, gave it type cursor , compression none, and set it as my cursor object's Cursor variable, and it didn't change my cursor.

    • @samyam
      @samyam  3 роки тому

      Did you make sure to attach the script to a gameobject? Also try calling the SetCursor in the Start method instead to see if that helps.

  • @Swatgoezhigh
    @Swatgoezhigh 3 роки тому

    controls.Enable(); and Disable() throws a NullReferenceException

    • @samyam
      @samyam  3 роки тому

      Did you instantiate the controls?
      controls = new CursorControls();

    • @Swatgoezhigh
      @Swatgoezhigh 3 роки тому

      @@samyam ok that helped :D

  • @OutCold9te6
    @OutCold9te6 3 роки тому

    I tried again with the Kenny assets and still nothing.

    • @OutCold9te6
      @OutCold9te6 3 роки тому

      I just got it to work by restarting Unity. Does that mean Unity bugged out?

    • @samyam
      @samyam  3 роки тому

      Maybe! Sometimes restarting fixes bugs and some issues

  • @fernandomilans8444
    @fernandomilans8444 4 роки тому +1

    Hi!
    In the console it throws me->
    InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
    and is because i have in many sides -> Input.GetMouseButtonDown(0), so only solution is Setting Active Input Handling to "Both"?

    • @samyam
      @samyam  4 роки тому

      Yes you should only be using the new input system if you enabled it, but you can switch to both to disable the errors

  • @srecky7822
    @srecky7822 3 роки тому

    why does unity change the way their code works every 2 seconds? this tutorial doesn't work anymore

    • @samyam
      @samyam  3 роки тому

      What do you mean? It should work. What issue are you having?

  • @eggwardosteve
    @eggwardosteve 2 роки тому

    It really feels like the video went way too fast. It was really hard to keep up, even with having to pause the video

    • @samyam
      @samyam  2 роки тому

      Sorry about that! I’ve been improving my pacing and speed in my more recent videos. Thanks for pointing it out!

  • @joeyhajj6038
    @joeyhajj6038 3 роки тому

    finally smthn useful

  • @14DimensionEnterprise
    @14DimensionEnterprise 3 роки тому

    why you circling mouse cursor? too annoying

    • @samyam
      @samyam  3 роки тому

      Yeah I know I need to work on that 😅 I don’t notice when I record