sbox-issues icon indicating copy to clipboard operation
sbox-issues copied to clipboard

`ControlObjectWidget`'s don't work on Serialized Object's created by `EditorUtility.GetSerializedObject`

Open Remscar opened this issue 1 month ago • 0 comments

Branch

staging

Describe the bug

In some editor code I am getting a serialized object via

var so = EditorUtility.GetSerializedObject( Settings )

Then I will try to make a widget to interact with these properties. This works on 99% of properties except for things like RangedFloatControlWidget which derives from ControlObjectWidget

The error is deep and non-descript but I tracked it down to this section of code in ControlObjectWidget

if ( property.TryGetAsObject( out var obj ) )
{
	SerializedObject = obj;
}

It fails to get the property as a SerializedObject

To Reproduce

public class MySettings {
  [Property]
  public RangedFloat BrushRotationAmount;
}
var Settings = new MySettings(); // define this elsewhere ideally
// Settings is MySettings class
var so = EditorUtility.GetSerializedObject( Settings )

var controlSheet = new ControlSheet();
controlSheet.AddRow( so.GetProperty( nameof( Settings.BrushRotationAmount) ) );


// Also creates the error
new RangedFloatControlWidget(so.GetProperty( nameof( Settings.BrushRotationAmount) );

Expected behavior

I should be able to do this. And if i'm not it should have a more clear error.

Media/Files

No response

Additional context

No response

Remscar avatar Nov 09 '25 20:11 Remscar