J Heschl
J Heschl

Reputation: 283

Variable annotated with [SerializeField] not showing up in inspector

I have a problem with a variable which is not showing up in the inspector even though I have declared it a serialized field.

Code:

using System;
using UnityEngine;
using UnityEngine.UIElements;

public class SettingsPopup : MonoBehaviour
{
    [SerializeField] private Slider speedSlider;

    private void Start()
    {
        speedSlider.value = PlayerPrefs.GetFloat("speed", 1);
    }
    ....
}

Unity inspector screenshot

I am using Unity 2019.2.10f1 Personal.
edit: changing the type of speedSlider to anything outside the UnityEngine.UIElements namespace makes it appear in the inspector.

Upvotes: 0

Views: 6969

Answers (2)

Boegi777
Boegi777

Reputation: 31

Try namespace UnityEngine.UI not UnityEngine.UIElements;

Upvotes: 3

Colin Young
Colin Young

Reputation: 3058

If you want a slider for the UI control, an attribute needs to be used to decorate the field, e.g. [Range(1, 100)]. The way the code is written it is asking the editor to use a control that allows the user to provide something of type Slider for the field value, rather than the intended float.

This will show a slider control in the editor:

[Range(1.0f, 100.0f)] public float speed;

Upvotes: 1

Related Questions