fix: search inactive objects when setActive=true in modify (#581)

When trying to activate an inactive GameObject via manage_gameobject modify with setActive=true, the lookup would fail because inactive objects were not included in the search by default.

Now automatically sets searchInactive=true when setActive=true is specified, allowing inactive objects to be found and activated.
main
dsarno 2026-01-19 07:04:54 -08:00 committed by GitHub
parent e617753b4e
commit 8252e6debc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 1 deletions

View File

@ -14,7 +14,15 @@ namespace MCPForUnity.Editor.Tools.GameObjects
{ {
internal static object Handle(JObject @params, JToken targetToken, string searchMethod) internal static object Handle(JObject @params, JToken targetToken, string searchMethod)
{ {
GameObject targetGo = ManageGameObjectCommon.FindObjectInternal(targetToken, searchMethod); // When setActive=true is specified, we need to search for inactive objects
// otherwise we can't find an inactive object to activate it
JObject findParams = null;
if (@params["setActive"]?.ToObject<bool?>() == true)
{
findParams = new JObject { ["searchInactive"] = true };
}
GameObject targetGo = ManageGameObjectCommon.FindObjectInternal(targetToken, searchMethod, findParams);
if (targetGo == null) if (targetGo == null)
{ {
return new ErrorResponse($"Target GameObject ('{targetToken}') not found using method '{searchMethod ?? "default"}'."); return new ErrorResponse($"Target GameObject ('{targetToken}') not found using method '{searchMethod ?? "default"}'.");