Skip to content

Commit db3a6c8

Browse files
committed
Relaxing prefab searching for model (fbx, glb, etc)
1 parent 65952c4 commit db3a6c8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Python/tools/asset_tools.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,20 @@ def import_asset(
7070
def instantiate_prefab(
7171
ctx: Context,
7272
prefab_path: str,
73+
prefab_suffix: str = ".prefab",
7374
position_x: float = 0.0,
7475
position_y: float = 0.0,
7576
position_z: float = 0.0,
7677
rotation_x: float = 0.0,
7778
rotation_y: float = 0.0,
78-
rotation_z: float = 0.0
79+
rotation_z: float = 0.0,
7980
) -> str:
8081
"""Instantiate a prefab into the current scene at a specified location.
8182
8283
Args:
8384
ctx: The MCP context
8485
prefab_path: Path to the prefab asset (relative to Assets folder)
86+
prefab_suffix: The suffix of the prefab file (default: ".prefab")
8587
position_x: X position in world space (default: 0.0)
8688
position_y: Y position in world space (default: 0.0)
8789
position_z: Z position in world space (default: 0.0)
@@ -94,6 +96,7 @@ def instantiate_prefab(
9496
"""
9597
try:
9698
unity = get_unity_connection()
99+
prefab_suffix = prefab_suffix.lower()
97100

98101
# Parameter validation
99102
if not prefab_path or not isinstance(prefab_path, str):
@@ -118,19 +121,19 @@ def instantiate_prefab(
118121
prefab_name = prefab_path.split('/')[-1]
119122

120123
# Ensure prefab has .prefab extension for searching
121-
if not prefab_name.lower().endswith('.prefab'):
122-
prefab_name = f"{prefab_name}.prefab"
123-
prefab_path = f"{prefab_path}.prefab"
124+
if not prefab_name.lower().endswith(prefab_suffix):
125+
prefab_name = f"{prefab_name}{prefab_suffix}"
126+
prefab_path = f"{prefab_path}{prefab_suffix}"
124127

125128
prefab_assets = unity.send_command("GET_ASSET_LIST", {
126-
"type": "Prefab",
127-
"search_pattern": prefab_name,
129+
"type": "Prefab" if prefab_suffix == ".prefab" else "GameObject",
130+
"search_pattern": prefab_name.removesuffix(prefab_suffix),
128131
"folder": prefab_dir
129132
}).get("assets", [])
130133

131134
prefab_exists = any(asset.get("path") == prefab_path for asset in prefab_assets)
132135
if not prefab_exists:
133-
return f"Prefab '{prefab_path}' not found in the project."
136+
return f"Prefab '{prefab_path}' not found in the project." + "\n" + str(prefab_assets)
134137

135138
response = unity.send_command("INSTANTIATE_PREFAB", {
136139
"prefab_path": prefab_path,

0 commit comments

Comments
 (0)