You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix(MCP): Resolve ValidTRS crash during component serialization
The Unity Editor was crashing with ValidTRS() assertions when attempting to get components from certain GameObjects like the Main Camera.
Investigation revealed the crash occurred during JSON serialization when reflection code accessed specific matrix properties (e.g., Camera.cullingMatrix, Transform.rotation, Transform.lossyScale). Accessing these properties appears to trigger internal Transform state validation failures, potentially due to interactions with the JSON serializer's reflection mechanism.
This fix addresses the issue by:
- Replacing LINQ iteration in GetComponentsFromTarget with a standard loop over a copied list to prevent potential premature serialization interactions.
- Explicitly skipping known problematic Camera matrix properties (cullingMatrix, pixelRect, rect) and generic matrix properties (worldToLocalMatrix, localToWorldMatrix) within GetComponentData's reflection logic.
- Retaining manual serialization for Transform component properties to avoid related reflection issues.
List<Component>componentsToIterate=newList<Component>(originalComponents??Array.Empty<Component>());// Copy immediately, handle null case
843
+
intcomponentCount=componentsToIterate.Count;
844
+
originalComponents=null;// Null the original reference
845
+
// Debug.Log($"[GetComponentsFromTarget] Found {componentCount} components on {targetGo.name}. Copied to list, nulled original. Starting REVERSE for loop...");
846
+
// --- End Copy and Null ---
847
+
848
+
varcomponentData=newList<object>();
849
+
850
+
for(inti=componentCount-1;i>=0;i--)// Iterate backwards over the COPY
851
+
{
852
+
Componentc=componentsToIterate[i];// Use the copy
853
+
if(c==null)
854
+
{
855
+
// Debug.LogWarning($"[GetComponentsFromTarget REVERSE for] Encountered a null component at index {i} on {targetGo.name}. Skipping.");
856
+
continue;// Safety check
857
+
}
858
+
// Debug.Log($"[GetComponentsFromTarget REVERSE for] Processing component: {c.GetType()?.FullName ?? "null"} (ID: {c.GetInstanceID()}) at index {i} on {targetGo.name}");
0 commit comments