Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Cursor Changing in Editor but not in Windows Standalone Build

Discussion in 'Scripting' started by PHOENIX05102000, Jan 7, 2023.

  1. PHOENIX05102000

    PHOENIX05102000

    Joined:
    Oct 14, 2022
    Posts:
    16
    I created a project for my university assignment and set a script for changing the cursor when on an object. The script works fine in the editor but when I build my project, the game cursor is the standard Windows cursor and not the custom one. The textures for the sprites for the custom cursor is set to Unity's Default Cursor Import settings. The project is build using Default Build settings for Windows with the Default Cursor in Player Settings set to the custom cursor. Could you tell me why it is happening. One more thing the Unity Version is 2021.3.11f1. The script for the cursor change is:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CursorChangeOnHoveringObject : MonoBehaviour
    6. {
    7.     public Texture2D EyeCursorTexture;
    8.     public Texture2D OriginalTexture;
    9.     public CursorMode cursorMode = CursorMode.ForceSoftware;
    10.     public Vector2 cursorHotspot = Vector2.zero;
    11.  
    12.     private void Awake()
    13.     {
    14.         Cursor.SetCursor(OriginalTexture, cursorHotspot, cursorMode);
    15.     }
    16.  
    17.     private void OnMouseEnter()
    18.     {
    19.         //if(other.gameObject.name == this.gameObject.name)
    20.         //{
    21.             Cursor.SetCursor(EyeCursorTexture, cursorHotspot, cursorMode);
    22.         //}
    23.     }
    24.  
    25.     private void OnMouseExit()
    26.     {
    27.         //if(collider.gameObject.name == this.gameObject.name)
    28.         //{
    29.             Cursor.SetCursor(OriginalTexture, cursorHotspot, cursorMode);
    30.         //}
    31.     }
    32.  
    33.     //private void OnMouseOver()
    34.     //{
    35.     //    Cursor.SetCursor(EyeCursorTexture, cursorHotspot, cursorMode);
    36.     //}
    37. }
    38.  
     
  2. PHOENIX05102000

    PHOENIX05102000

    Joined:
    Oct 14, 2022
    Posts:
    16
    I got it to be fixed by enabling Read/Write in Cursor Texture Import Settings.
     
  3. michael_unity387

    michael_unity387

    Joined:
    Feb 2, 2021
    Posts:
    5
    This worked for me as well.