Skip to content

Fix UseToStringAsLabel on SubclassSelector attribute - #99

Merged
mackysoft merged 5 commits into
mackysoft:mainfrom
jhodk:fix/use-to-string-as-label
Oct 14, 2026
Merged

mackysoft merged 5 commits into
mackysoft:mainfrom
jhodk:fix/use-to-string-as-label

Conversation

@jhodk

@jhodk jhodk commented Mar 6, 2026

Copy link
Copy Markdown

Description

I am using unity editor version 6000.3.7f1.
The property UseToStringAsLabel on the SubclassSelector attribute does not currently appear to have any impact on the GUI render.

According to this code on the current main branch, we would expect the foodThree example field to be rendered in the editor with label "Grape".

// UseToStringAsLabel support on UNITY_2021_3_OR_NEWER
[SerializeReference, SubclassSelector(UseToStringAsLabel = true)]
public Food foodThree = new Grape();

However the left side of the screenshot below shows that is not the case - the name remains as "Food Three".

Changes made

  • Moved EditorGUI.BeginProperty calls after the label.text override.
  • Added ToString override in Food example class
  • Added list Foods Three to Example script with UseToStringAsLabel = true

Screenshots

Left is before the fix, Right is after the fix
image

Thanks.

jhodk and others added 5 commits March 6, 2026 23:33
Why
BeginProperty needs the prepared label and should share its drawing boundary with EndProperty.

What Changed
Prepare ToString labels before one common BeginProperty call, then select the managed reference or warning rendering path.

Impact
Preserves null, mixed value, custom drawer, and invalid property behavior while keeping the property scope in one place.
Why
The list is configured through the Inspector and does not need to be public.

What Changed
Make foodsThree private while retaining its SerializeReference and SubclassSelector attributes.

Impact
Keeps the existing serialized field name, scene data, and Inspector example behavior.
Why
The added example should pass the complete pull request whitespace check.

What Changed
Remove trailing spaces from the blank line before foodsThree.

Impact
Changes formatting only.
@mackysoft
mackysoft merged commit 7c81c92 into mackysoft:main Oct 14, 2026
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants