fix: Enable private field access in UpdateComponentTool#106
fix: Enable private field access in UpdateComponentTool#106CharlieHess wants to merge 1 commit intoCoderGamester:mainfrom
Conversation
Use SerializedObject API as primary method for modifying component fields, with enhanced reflection as fallback. This fixes three issues: 1. Private fields in base classes now accessible (recursive type search) 2. Asset references can be set by path or GUID 3. Nested field paths supported via SerializedObject.FindProperty() Co-authored-by: Cursor <cursoragent@cursor.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@CoderGamester This is admittedly a Cursor / Opus collaboration but for verification I'm able to wire up event listeners now, using my fork, and prior to that I was stuck on these! |
| /// <param name="componentData">The data to apply to the component</param> | ||
| /// <param name="errorMessage">Error message if any fields failed to update</param> | ||
| /// <returns>True if all fields were updated successfully</returns> | ||
| private bool UpdateComponentDataSerialized(Component component, JObject componentData, out string errorMessage) |
There was a problem hiding this comment.
Is this being used somewhere?
My IDE marks as no refereces
| // Skip null values | ||
| if (string.IsNullOrEmpty(fieldName) || fieldValue.Type == JTokenType.Null) | ||
| // Skip null field names | ||
| if (string.IsNullOrEmpty(fieldName)) |
There was a problem hiding this comment.
why removing the fieldValue.Type == JTokenType.Null check?
Problem
The
update_componenttool fails when trying to modify:_eventReference._eventare unsupportedRoot cause:
GetField()only searches the immediate type, and the existingUnityEngine.Objecthandler doesn't load assets.Solution
Hybrid approach using SerializedObject API as primary, with enhanced reflection as fallback:
SerializedObject.FindProperty()automatically handles base class fields and nested pathsGetFieldRecursive()/GetPropertyRecursive()helpers traverse the type hierarchy for non-serialized propertiesSetSerializedPropertyValue()handles allSerializedPropertyTypecases includingObjectReferencewith asset path/GUID supportConvertJTokenToValue()updated to load assets by path (Assets/...), GUID ({guid: "..."}), or name searchUsage Examples