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. Dismiss Notice

How to disable slider interaction?

Discussion in 'UI Toolkit' started by liphttam1, Apr 28, 2022.

?

How're you doing today?

  1. Fine, thanks.

    12 vote(s)
    70.6%
  2. Good, thanks.

    5 vote(s)
    29.4%
  1. liphttam1

    liphttam1

    Joined:
    Nov 11, 2014
    Posts:
    9
    Using Unity 2021.3.1f1 LTS, I've created a slider which I do not want to be able to interact with.

    (Or rather I want to be able to disable interaction and enable it as needed but for the purposes of this question I just need to be able to have a slider I can't interact with.)

    I was under the impression that changing focusable to false would make it so it can't be interacted with. It works that way for text fields.

    My code is essentially as follows:
    Code (CSharp):
    1. Slider slider = menu.Q<Slider>("SliderInput");
    2. slider.focusable = false;
    However simply dragging a new slider into the scene and changing it's focusable attribute to false doesn't disable it either. What am I missing here?
     
  2. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    90
    MatanYamin and liphttam1 like this.
  3. liphttam1

    liphttam1

    Joined:
    Nov 11, 2014
    Posts:
    9
    Ah that's it thank you.

    I had assumed that that would change the visibility of the slider and affect my layout so I didn't even think to try it.

    And as an aside, can you modify "enabled" in the UiBuilder? I think not being able to find/see it in the UiBuilder contributed to me not trying it.
     
  4. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    90
    Sadly, it's not possible to modify "enabled" in the builder right now. We do have this task in our backlog though :)
     
    liphttam1 likes this.
  5. LarsLundh

    LarsLundh

    Joined:
    Sep 6, 2022
    Posts:
    20
    Hello!

    Since Writing the below text my colleague recommended this:
    Code (CSharp):
    1.             this.Q<Slider>("FocalDistanceSlider").SetEnabled(false);
    2.             this.Q<Slider>("FocalDistanceSlider").style.opacity = 1.0f;
    bearing in mind:
    upload_2023-4-6_10-12-17.png


    The Below Text
    I want to disable the slider for user interaction but allow the events to continue and I also do not want to inherit the greyed out styling. I want a display only slider (Like a needle indicator)

    I want a normal slider that you can NOT drag.

    how would I achieve that?

    In other UI tools you would toggle sensitivity to false.
    a cool name would be Interactable
     
    Last edited: Apr 6, 2023