Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PropertyDrawer, Rect position

Discussion in 'Editor & General Support' started by StrongCube, Jun 15, 2019.

  1. StrongCube

    StrongCube

    Joined:
    Nov 22, 2016
    Posts:
    50
    Rect position in PropertyDrawer produces two different results, why? How to get one and the right one? The desired width of the property.


    [CustomPropertyDrawer(typeof(MinMaxSlider))]
    public class MinMaxSliderDrawer : PropertyDrawer
    {

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {

    Debug.Log(position); <-------



    upload_2019-6-15_12-13-43.png
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I recommend this Unity blog article.

    Basically, OnGUI is called multiple times per frame with different meanings. In your case you are seeing two separate rect because during the layout event, the rect starts at zero and is built by looking at all other control. Only later during rect do you receive the final size. And this is all ok and works for all builtin controls. You only need to deal with these events when you are building custom controls.

    Is there a reason why the zero rect is causing problems or were you only asking out of interest?