Skip to content

Commit 69336bc

Browse files
authored
6645 ue5 fixes (#10)
Workarounds for: - Mac - Linux - U5 dev where Shotgun components were renamed to Shotgrid, without backward compatibility in mind.
1 parent 42250cb commit 69336bc

File tree

4 files changed

+106
-32
lines changed

4 files changed

+106
-32
lines changed

hooks/tk-multi-publish2/basic/collector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def collect_selected_assets(self, parent_item):
136136
:param parent_item: Parent Item instance
137137
"""
138138
unreal_sg = sgtk.platform.current_engine().unreal_sg_engine
139-
140139
# Iterate through the selected assets and get their info and add them as items to be published
141140
for asset in unreal_sg.selected_assets:
142141
asset_name = str(asset.asset_name)

plugins/basic/bootstrap.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44

55
import sys
66
import os
7+
import unreal
78

89
# Setup sys.path so that we can import our bootstrapper.
910
plugin_root_dir = os.path.abspath(os.path.dirname(__file__))
1011
sys.path.insert(0, os.path.join(plugin_root_dir, "python"))
1112

13+
# Temp workaround for UE5 dev: for some reasons the core/python path is missing
14+
# in sys.path but is present in the PYTHONPATH.
15+
# Make sure sys.path is up to date with what is in the PYTHON PATH
16+
python_path = os.environ.get("PYTHONPATH") or ""
17+
for path in python_path.split(os.pathsep):
18+
# We can have empty entries for consecutives separators
19+
if path and path not in sys.path:
20+
unreal.log_warning(
21+
"Adding missing %s Python path to sys paths" % path,
22+
)
23+
sys.path.append(path)
24+
1225
from tk_unreal_basic import plugin_bootstrap
1326
plugin_bootstrap.bootstrap_plugin(plugin_root_dir)

plugins/basic/python/tk_unreal_basic/plugin_bootstrap.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ def _on_engine_initialized():
6868
sgtk_logger.debug("tk-unreal finished initialization.")
6969

7070
import unreal
71-
72-
unreal.ShotgunEngine.get_instance().on_engine_initialized()
71+
if hasattr(unreal, "ShotgridEngine"):
72+
unreal.ShotgridEngine.get_instance().on_engine_initialized()
73+
else:
74+
unreal.ShotgunEngine.get_instance().on_engine_initialized()
7375

7476

7577
def _initialize_manager(plugin_root_path):

python/tk_unreal/unreal_sg_engine.py

Lines changed: 89 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,84 @@
88
import sys
99
import os
1010

11-
unreal.log("Loading Shotgun Engine for Unreal from {}".format(__file__))
11+
unreal.log("Loading SG Engine for Unreal from {}".format(__file__))
12+
13+
# Shotgun integration components were renamed to Shotgrid from UE5
14+
if hasattr(unreal, "ShotgridEngine"):
15+
UESGEngine = unreal.ShotgridEngine
16+
17+
else:
18+
UESGEngine = unreal.ShotgunEngine
1219

1320

1421
@unreal.uclass()
15-
class ShotgunEngineWrapper(unreal.ShotgunEngine):
22+
class ShotgunEngineWrapper(UESGEngine):
1623

1724
def _post_init(self):
1825
"""
1926
Equivalent to __init__ but will also be called from C++
2027
"""
2128
config.wrapper_instance = self
2229

23-
@unreal.ufunction(override=True)
24-
def get_shotgun_menu_items(self):
25-
"""
26-
Returns the list of available menu items to populate the Shotgun menu in Unreal
27-
"""
28-
menu_items = []
29-
30-
engine = sgtk.platform.current_engine()
31-
menu_items = self.create_menu(engine)
32-
33-
unreal.log("get_shotgun_menu_items returned: {0}".format(menu_items.__str__()))
34-
35-
return menu_items
30+
# Shotgun integration components were renamed to Shotgrid from UE5
31+
if hasattr(UESGEngine, "get_shotgrid_menu_items"):
32+
@unreal.ufunction(override=True)
33+
def get_shotgrid_menu_items(self):
34+
"""
35+
Returns the list of available menu items to populate the SG menu in Unreal.
36+
"""
37+
menu_items = []
38+
39+
engine = sgtk.platform.current_engine()
40+
menu_items = self.create_menu(engine)
41+
42+
unreal.log("get_shotgrid_menu_items returned: {0}".format(menu_items.__str__()))
43+
44+
return menu_items
45+
46+
def get_shotgun_menu_items(self):
47+
"""
48+
Provide backward compatibility.
49+
"""
50+
return self.get_shotgrid_menu_items()
51+
else:
52+
@unreal.ufunction(override=True)
53+
def get_shotgun_menu_items(self):
54+
"""
55+
Returns the list of available menu items to populate the SG menu in Unreal.
56+
"""
57+
menu_items = []
58+
59+
engine = sgtk.platform.current_engine()
60+
menu_items = self.create_menu(engine)
61+
62+
unreal.log("get_shotgun_menu_items returned: {0}".format(menu_items.__str__()))
63+
64+
return menu_items
65+
66+
def get_shotgrid_menu_items(self):
67+
"""
68+
Provide forward compatibility.
69+
"""
70+
return self.get_shotgun_menu_items()
71+
72+
if hasattr(UESGEngine, "get_shotgrid_work_dir"):
73+
def get_shotgun_work_dir(self, *args, **kwargs):
74+
"""
75+
Provide backward compatibility.
76+
"""
77+
return self.get_shotgrid_work_dir(*args, **kwargs)
78+
else:
79+
def get_shotgrid_work_dir(self, *args, **kwargs):
80+
"""
81+
Provide forward compatibility.
82+
"""
83+
return self.get_shotgun_work_dir(*args, **kwargs)
3684

3785
@unreal.ufunction(override=True)
3886
def execute_command(self, command_name):
3987
"""
40-
Callback to execute the menu item selected in the Shotgun menu in Unreal
88+
Callback to execute the menu item selected in the SG menu in Unreal.
4189
"""
4290
engine = sgtk.platform.current_engine()
4391

@@ -58,9 +106,9 @@ def _get_command_override(self, engine, command_name, default_callback):
58106
:param command_name: The command name to override
59107
:param default_callback: The callback to use when there's no override
60108
"""
61-
# Override the Shotgun Panel command to use the Shotgun Entity context
109+
# Override the SG Panel command to use the SG Entity context
62110
# and also reuse the dialog if one already exists
63-
if command_name == "Shotgun Panel...":
111+
if command_name in ["Shotgun Panel...", "ShotGrid Panel..."]:
64112
def show_shotgunpanel_with_context():
65113
app = engine.apps["tk-multi-shotgunpanel"]
66114
entity_type, entity_id = self._get_context(engine)
@@ -75,7 +123,7 @@ def show_shotgunpanel_with_context():
75123

76124
def _get_context_url(self, engine):
77125
"""
78-
Get the Shotgun entity URL from the metadata of the selected asset, if present
126+
Get the SG entity URL from the metadata of the selected asset, if present.
79127
"""
80128
# By default, use the URL of the project
81129
url = engine.context.shotgun_url
@@ -110,12 +158,12 @@ def _get_context_url(self, engine):
110158

111159
def _get_context(self, engine):
112160
"""
113-
Get the Shotgun context (entity type and id) that is associated with the selected menu command
161+
Get the SG context (entity type and id) that is associated with the selected menu command.
114162
"""
115163
entity_type = None
116164
entity_id = None
117165

118-
# The context is derived from the Shotgun entity URL
166+
# The context is derived from the SG entity URL
119167
url = self._get_context_url(engine)
120168
if url:
121169
# Extract entity type and id from URL, which should follow this pattern:
@@ -173,7 +221,7 @@ def shutdown(self):
173221

174222
engine = sgtk.platform.current_engine()
175223
if engine is not None:
176-
unreal.log("Shutting down ShotgunEngineWrapper")
224+
unreal.log("Shutting down %s" % self.__class__.__name__)
177225

178226
# destroy_engine of tk-unreal will take care of closing all dialogs that are still opened
179227
engine.destroy()
@@ -184,12 +232,12 @@ def shutdown(self):
184232
Menu generation functionality for Unreal (based on the 3ds max Menu Generation implementation)
185233
186234
Actual menu creation is done in Unreal
187-
The following functions simply generate a list of available commands that will populate the Shotgun menu in Unreal
235+
The following functions simply generate a list of available commands that will populate the SG menu in Unreal
188236
"""
189237

190238
def create_menu(self, engine):
191239
"""
192-
Populate the Shotgun Menu with the available commands
240+
Populate the SG Menu with the available commands.
193241
"""
194242
menu_items = []
195243

@@ -257,9 +305,13 @@ def _add_menu_item_from_command(self, menu_items, command):
257305

258306
def _add_menu_item(self, menu_items, type, name="", title="", description=""):
259307
"""
260-
Adds a new Unreal ShotgunMenuItem to the menu items
308+
Adds a new Unreal SG MenuItem to the menu items.
261309
"""
262-
menu_item = unreal.ShotgunMenuItem()
310+
# Shotgun integration components were renamed to Shotgrid from UE5
311+
if hasattr(unreal, "ShotgridMenuItem"):
312+
menu_item = unreal.ShotgridMenuItem()
313+
else:
314+
menu_item = unreal.ShotgunMenuItem()
263315
menu_item.title = title
264316
menu_item.name = name
265317
menu_item.type = type
@@ -275,15 +327,23 @@ def _start_contextual_menu(self, engine, menu_items):
275327

276328
self._add_menu_item(menu_items, "context_begin", ctx_name, ctx_name)
277329

278-
engine.register_command("Jump to Shotgun", self._jump_to_sg, {"type": "context_menu", "short_name": "jump_to_sg"})
330+
engine.register_command(
331+
"Jump to ShotGrid",
332+
self._jump_to_sg,
333+
{"type": "context_menu", "short_name": "jump_to_sg"}
334+
)
279335

280336
# Add the menu item only when there are some file system locations.
281337
if ctx.filesystem_locations:
282-
engine.register_command("Jump to File System", self._jump_to_fs, {"type": "context_menu", "short_name": "jump_to_fs"})
338+
engine.register_command(
339+
"Jump to File System",
340+
self._jump_to_fs,
341+
{"type": "context_menu", "short_name": "jump_to_fs"}
342+
)
283343

284344
def _jump_to_sg(self):
285345
"""
286-
Callback to Jump to Shotgun from context
346+
Callback to Jump to SG from context.
287347
"""
288348
from sgtk.platform.qt5 import QtGui, QtCore
289349
url = self._get_context_url(sgtk.platform.current_engine())

0 commit comments

Comments
 (0)