-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Enum reflection sensor #4006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum reflection sensor #4006
Conversation
@@ -185,7 +185,7 @@ static ISensor CreateReflectionSensor(object o, FieldInfo fieldInfo, PropertyInf | |||
memberType = propertyInfo.PropertyType; | |||
} | |||
|
|||
if (!s_TypeToSensorInfo.ContainsKey(memberType)) | |||
if (!s_TypeToSensorInfo.ContainsKey(memberType) && !memberType.IsEnum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be to add enum types to s_TypeToSensorInfo as they're requested. That simplifies the logic a bit later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a minor comment but looks good to me
i++; | ||
} | ||
|
||
writer[i] = knownValue ? 0.0f : 1.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that the dimension of an enum will be n + 1 where n is the number of possible values.
This might be confusing to users and I think returning an array of zeros when the value was none of the possible ones is fair.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with @vincentpierre's comment. It seems intuitive to keep the observation all 0's if there was no known enum value selected. Otherwise, looks good.
I made those changes, and also figured out how to support Flags. Non-flags will use all zeros for unknown values. Flags will OR the value with each defined flag. |
Proposed change(s)
Allow enums with ObservableAttribute. Since the number of possibilities is known ahead of time, we can treat this as a one-hot encoding.
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
https://jira.unity3d.com/browse/MLA-1007
Types of change(s)
Checklist
Other comments