-
Notifications
You must be signed in to change notification settings - Fork 462
Description
When running the MCPForUnity editor tooling, the following warning is logged by Unity:
Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead. System.Reflection.PropertyInfo:GetValue (object) MCPForUnity.Editor.Helpers.GameObjectSerializer:GetComponentData (UnityEngine.Component,bool) (at ./Library/PackageCache/com.coplaydev.unity-mcp@c7cf9cd32067/Editor/Helpers/GameObjectSerializer.cs:359) MCPForUnity.Editor.Tools.ManageGameObject:GetComponentsFromTarget (string,string,bool) (at ./Library/PackageCache/com.coplaydev.unity-mcp@c7cf9cd32067/Editor/Tools/ManageGameObject.cs:971) MCPForUnity.Editor.Tools.ManageGameObject:HandleCommand (Newtonsoft.Json.Linq.JObject) (at ./Library/PackageCache/com.coplaydev.unity-mcp@c7cf9cd32067/Editor/Tools/ManageGameObject.cs:157) MCPForUnity.Editor.MCPForUnityBridge:ExecuteCommand (MCPForUnity.Editor.Models.Command) (at ./Library/PackageCache/com.coplaydev.unity-mcp@c7cf9cd32067/Editor/MCPForUnityBridge.cs:1053) MCPForUnity.Editor.MCPForUnityBridge:ProcessCommands () (at ./Library/PackageCache/com.coplaydev.unity-mcp@c7cf9cd32067/Editor/MCPForUnityBridge.cs:894) UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
Expected behaviour
Editor tooling should use renderer.sharedMaterial
when inspecting or serialising component data during edit mode, to avoid instantiating materials and leaking them into the scene.
Actual behaviour
The code path in GameObjectSerializer.GetComponentData
calls renderer.material
in edit mode, which causes Unity to create unique material instances and logs warnings.
Steps to reproduce
- Open Unity editor with MCPForUnity installed
- Trigger any action that runs
ManageGameObject.GetComponentsFromTarget
in edit mode - Observe console warnings about
renderer.material
instantiation
Suggested fix
Update editor-side reflection/serialization code to use renderer.sharedMaterial
when accessing Material
properties during edit mode.