Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by strangecloudsworkmail · Jan 01, 2019 at 09:25 AM · uisorting ordermouse cursor

Custom Cursor is hidden by UI

My custom mouse cursor is going behind the UI elements, instead of being in-front.

the mouse cursor object just has a transform, sprite renderer, and a simple mouse script that simply updates the position of the image and hides the real cursor.

The mouse cursor is a game object I've placed up a canvas with no other objects, and I have set that canvas sort order to as high as possible 32,767. all the other canvas's sort order is under 30. However this the image is still going behind all the other stuff for some reason.

Any help would be greatly appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by strangecloudsworkmail · Jan 01, 2019 at 09:25 PM

Ok, so I figured it out. What I had was a gameobject with: "Transform, sprite renderer, and my custom FollowMouse script." What I needed was a rect transform, Image, and the script on my cursor object. The parent canvas should be set to "Overlay." I had to do a bit of tweaking to my script to get the point to follow the cursor properly, but the image is appearing on top everything now.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Maine1992 · Apr 03, 2020 at 08:35 AM 0
Share

Hi - I am having the same problem. I made the changes as you did, but my cursor is for some weird reason stuck in the corner of the screen. Guess it has something to do with the sprite renderer. So my question is - what did you change in your script in order for it to work?

avatar image unity_h1nnXKtTObKm0g Maine1992 · Jan 25, 2021 at 10:48 PM 1
Share

The fix here is to set transform.position to Input.mousePosition;

You might find examples of this... Camera.main.ScreenToWorldPoint(Input.mousePosition);

Unfortunately this won't work as expected and you'll end up with a cursor stuck at the corner of your screen.

So instead, in your GameCursor script just use public class GameCursor : $$anonymous$$onoBehaviour { // Start is called before the first frame update void Start() { Cursor.visible = false; }

     // Update is called once per frame
     void Update()
     {
         // Notice this won't work
         // Vector2 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 
         // Instead just use this
         transform.position = Input.mousePosition;
     }
 }

avatar image unity_h1nnXKtTObKm0g unity_h1nnXKtTObKm0g · Jan 25, 2021 at 10:53 PM 0
Share

You'll probably also want to uncheck the "Raycast Target" on your Image Component since it will detect any onClick events at the Cursor Game Object itself rather than registering to your UI Elements underneath (ie. buttons)

avatar image
0

Answer by LogicBlade · Oct 09, 2020 at 01:30 AM

I was able to get my custom cursor to appear by making my cursor gameObject a child of the canvas.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

166 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

4.6 UI sort order in fornt of IMGUI/OnGUI possible? 2 Answers

Place UI text on top of other elements in 2D 1 Answer

Z-order of uGUI elements 2 Answers

UI Canvas sorting with custom UI Shader 1 Answer

UI Bring to front without modifying hierarchy 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges