Skip to content

fix: Enable private field access in UpdateComponentTool#106

Open
CharlieHess wants to merge 1 commit intoCoderGamester:mainfrom
CharlieHess:fix/private-field-access
Open

fix: Enable private field access in UpdateComponentTool#106
CharlieHess wants to merge 1 commit intoCoderGamester:mainfrom
CharlieHess:fix/private-field-access

Conversation

@CharlieHess
Copy link
Contributor

Problem

The update_component tool fails when trying to modify:

  1. Asset references - ScriptableObjects cannot be set by path or GUID
  2. Nested fields - dot-notation paths like _eventReference._event are unsupported
  3. Private serialized fields in base classes - we're not searching the inheritance hierarchy

Root cause: GetField() only searches the immediate type, and the existing UnityEngine.Object handler 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 paths
  • New GetFieldRecursive() / GetPropertyRecursive() helpers traverse the type hierarchy for non-serialized properties
  • SetSerializedPropertyValue() handles all SerializedPropertyType cases including ObjectReference with asset path/GUID support
  • ConvertJTokenToValue() updated to load assets by path (Assets/...), GUID ({guid: "..."}), or name search

Usage Examples

// Asset by path
{"_eventReference._event": "Assets/Events/MyEvent.asset"}

// Asset by GUID
{"_eventReference._event": {"guid": "95c910ab954254d98a9165e47e87ec9f"}}

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>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CharlieHess
Copy link
Contributor Author

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!

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.

1 participant