@@ -70,18 +70,20 @@ def import_asset(
70
70
def instantiate_prefab (
71
71
ctx : Context ,
72
72
prefab_path : str ,
73
+ prefab_suffix : str = ".prefab" ,
73
74
position_x : float = 0.0 ,
74
75
position_y : float = 0.0 ,
75
76
position_z : float = 0.0 ,
76
77
rotation_x : float = 0.0 ,
77
78
rotation_y : float = 0.0 ,
78
- rotation_z : float = 0.0
79
+ rotation_z : float = 0.0 ,
79
80
) -> str :
80
81
"""Instantiate a prefab into the current scene at a specified location.
81
82
82
83
Args:
83
84
ctx: The MCP context
84
85
prefab_path: Path to the prefab asset (relative to Assets folder)
86
+ prefab_suffix: The suffix of the prefab file (default: ".prefab")
85
87
position_x: X position in world space (default: 0.0)
86
88
position_y: Y position in world space (default: 0.0)
87
89
position_z: Z position in world space (default: 0.0)
@@ -94,6 +96,7 @@ def instantiate_prefab(
94
96
"""
95
97
try :
96
98
unity = get_unity_connection ()
99
+ prefab_suffix = prefab_suffix .lower ()
97
100
98
101
# Parameter validation
99
102
if not prefab_path or not isinstance (prefab_path , str ):
@@ -118,19 +121,19 @@ def instantiate_prefab(
118
121
prefab_name = prefab_path .split ('/' )[- 1 ]
119
122
120
123
# 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 } "
124
127
125
128
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 ) ,
128
131
"folder" : prefab_dir
129
132
}).get ("assets" , [])
130
133
131
134
prefab_exists = any (asset .get ("path" ) == prefab_path for asset in prefab_assets )
132
135
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 )
134
137
135
138
response = unity .send_command ("INSTANTIATE_PREFAB" , {
136
139
"prefab_path" : prefab_path ,
0 commit comments