Can't find variable in inspector. Any reason why this might've happened?

I was trying to make a slider element in my settings menu to allow the player to change the mouse sensitivity on a range of 0.1 to 7, but when I added a Slider variable, I couldn’t see it in the inspector, (Image below) which meant I couldn’t properly set it’s value.

9438770--1323914--upload_2023-10-29_19-3-44.png

Here’s a bit of my code to further explain what I mean:

using System;
using UnityEngine;
using UnityEngine.UIElements;

[RequireComponent(typeof(CharacterController))]

public class FPSController : MonoBehaviour
{

    [Range(0.1f, 7f)]
    public float lookSpeed = 2f;
    private readonly Slider lookSpeedSlider;
    //other variables

    void Update() {
        lookSpeed = lookSpeedSlider.value;
        //more irrelevant code
    }
}

Any help is appreciated, whether it’s a solution, further explenations/instructions on what to do or a work-around.

thanks in advance.

Try making the field public instead of private.

1 Like

Tried that, same result sadly.

Edit: I also added a [SerializeField] and removed the readonly attribute but it still didn’t work.

Your code above presumably is trying to use UnityEngine.UIElements.Slider

Are you perhaps looking for UnityEngine.UI.Slider?

2 Likes

On top of the above, Unity also can’t serialise readonly fields.

2 Likes

Thanks, it worked!