- Home /
How to display a serialized property inside a min max slider?
Hy Everyone, I am trying to display a min max slider to control a float variable inside my target class. But I Keep getting the error saying that I have a problem with the overload method. I think this is because I nedd to cast my serialized property as (float) inside the min max slider method, but I still get the same error. Any ideas?
Obs: I am creating a Flies System (non particle based) asset to publish for FREE on asset store, so, your help is very appreciated!
Thanks everyone! =)
using UnityEngine;
using UnityEditor;
[CustomEditor (typeof(FliesSystem))]
public class FliesSystemEditor : Editor {
private SerializedObject instance;
private SerializedProperty minVelocity;
private SerializedProperty maxVelocity;
public void OnEnable()
{
if(instance == null) instance = new SerializedObject(target);
minVelocity = instance.FindProperty("minVelocity");
maxVelocity = instance.FindProperty("maxVelocity");
}
public override void OnInspectorGUI()
{
instance.Update();
EditorGUILayout.MinMaxSlider(ref minVelocity, ref maxVelocity, 0f,10f);
instance.ApplyModifiedProperties();
}
}
Answer by frarees · Mar 19, 2014 at 07:18 PM
Wrap your property implementation using EditorGUI.BeginProperty and EditorGUI.EndProperty as done here.
Use SerializedProperty API to access the serialized value (e.g. floatValue
... use type
to identify which type is holding that property).
Hi man, thank you for the answer. I will check it out soon and give give you some feedback! Thanks!
Hi! I am reading the documentation, its all too confusing for me. For instance, why the heck do I need to specify a rect around my property, and how is it done? I can't find any example of that. I guess the documentation is lacking some clarity around these topics yet. Anyway, I'll keep trying. Thanks!
How always need to specify a rect (unless using GUILayout, which would do it internally for you). I highly recommend inspecting the UnityEditor assembly to see how Unity works internally with them. Good luck!
Why don't you simply use EditorGUILayout.IntSlider(SerializedProperty property, int leftValue, int rightValue, GUIContent label, params GUILayoutOption[] options) ? Wasn't this function available back in 2014?
Answer by EugeneJefferson · Nov 23, 2020 at 10:32 PM
in target class [SerializeField, Range(0f, 1f)] protected float val = 0;
in Editor Class EditorGUILayout.PropertyField(serializedObject.FindProperty("val"));
Your answer
![](https://koobas.hobune.stream/wayback/20220613140617im_/https://answers.unity.com/themes/thub/images/avi.jpg)